zoukankan      html  css  js  c++  java
  • Node.js-Error

    Node.js-Error

    Node.js Error: Cannot find module express的解决办法

    1.全局安装express框架,cmd打开命令行,输入如下命令:
            npm install -g express
       express 4.x版本中将命令工具分出来,安装一个命令工具,执行命令:
            npm install -g express-generator
       输入express --version验证

    2.如果在执行js文件仍报Error: Cannot find module express错误。
    在自己的工程目录下再次执行: npm install express
    ————————————————
    版权声明:本文为CSDN博主「mlsama」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/mlsama/article/details/80211033

    TypeError: Router.use() requires a middleware function but got a Object

    写路由模块的时候忘记导出路由 module.exports = router

    Router 传入全局变量

    实现1:module.exports

    index.js
    var Dev = require('./Routes/Dev.js');
    app.use('/Dev', Dev(app));
    
    Router.js
    var appObj = null;
    module.exports = function(app){
    //响应全局变量
    appObj = app;
    return router;
    }
    

    EasyUI DataGrid

    方法loadData 加载空参数时

    $('#TT').datagrid('loadData',{"total":0,"rows":[]})

    参数queryParams使用

    • get
      在req的query属性内能看到参数
    • post
      在req的body属性内能看到参数
    • Error:
      在使用Router时,post方法没有看到body,需要bodyParser。
      在Router内:
      var express = require('express');
      var router = express.Router();
      var bodyParser = require('body-parser');
      router.use(bodyParser());
      router.use(bodyParser.urlencoded({extended:true}));
      

    在easyui DataGrid 中使用 linkbutton

    如果直接在 field 的 formatter 中直接 return 一个linkbutton 按钮,则无法显示图标,只有普通的 a 标签,无法加载样式,因为easyui 只在页面加载时渲染标签,因此在使用formatter格式化列数据后,动态添加的linkbutton样式无法渲染样式,需要在 datagrid 加载完后进行重新渲染,使用 onLoadSuccess 进行对 linkbutton渲染
    $('.classname').linkbutton({text:"test",plain:'true',iconCls:'icon-add'});
    ————————————————
    版权声明:本文为CSDN博主「宝贝一路向前」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/xcmonline/java/article/details/52944026

    styler:cellStyler

    	<table id="TT" class="easyui-datagrid" title="DataGrid Cell Style" style="700px;height:250px"
    			data-options="
    				singleSelect: true,
    				iconCls: 'icon-save'
    			">
    		<thead>
    			<tr>
    				<th data-options="field:'itemid',80">Item ID</th>
    				<th data-options="field:'productid',100">Product</th>
    				<th data-options="field:'listprice',80,align:'right',styler:cellStyler">List Price</th>
    				<th data-options="field:'unitcost',80,align:'right'">Unit Cost</th>
    				<th data-options="field:'attr1',250">Attribute</th>
    				<th data-options="field:'status',60,align:'center'">Status</th>
    			</tr>
    		</thead>
    	</table>
    	<script type="text/javascript">
    		$(function () {
    			loadDevMonitorList();
    		});
    		function loadDevMonitorList(){
    			$('#TT').datagrid('loadData',{"total":0,"rows":[{
    			"itemid": 0,
    			"listprice": "1"},
    			{
    			"itemid": 1,
    			"listprice": "31"},
    			{
    			"itemid": 2,
    			"listprice": "100"}]})
    		};
    
    		function cellStyler(value,row,index){
    			if (value){
    				return 'background-color:#ffee00;color:red;';
    			}
    		}
    	</script>
    

    注意,如果用脚本重新加载数据,要在加载的时候加上styler:cellStyler

     	$('#Info').datagrid({
            url:'D1/getD2',
            queryParams:{
                D1ID: D1Id
            },
            method:'post',
            fitColumns : true,//自动设置列的宽度
            singleSelect : true,//单选
            striped:true,//条纹
            //height:400,
            pagination:true,//翻页或滚动
            GridLines:'Horizontal',
            columns:[[
                {field:'T',title:'T',styler:cellStyler}
            ]]
        });
    

    nodejs中req.body 为空的问题

    WebSite
    随着express升级,bodyParser从express中被分离了出来,因此,在使用express新版本的时候,需要npm install body-parser 来安装bodyParser。
    在app.js中要引入bodyParser。
    var bodyParser = require('body-parser');
    其次,需要在app.js中use bodyParser。
    app.use(bodyParser());
    最后,需要给bodyParser提供参数。
    'Content-Type': 'application/x-www-form-urlencoded'
    对于bodyParser的参数,根据需要解析的文件类型来进行设置,参数类型有很多种,可以查看具体文献。

    如何发现3中的有过期的情况,将改为app.use(bodyParser.urlencoded({extended:false}));

  • 相关阅读:
    linux添加开机启动项、登陆启动项、定时启动项、关机执行项等的方法
    linux下/etc/rc.d目录的介绍及redhat启动顺序
    Linux开机自动挂载存储的两种方式
    Linux中环境变量文件profile、bashrc、bash_profile之间的区别和联系
    linux命令详解——yum
    linux命令详解——ftp
    Shell脚本之sed详解
    shell awk读取文件中的指定行的指定字段
    MySQL的字符集
    shell脚本中的数组
  • 原文地址:https://www.cnblogs.com/yongchao/p/13276094.html
Copyright © 2011-2022 走看看