使用easyUI,datagrid绑定数据的问题

咻呶呶氏 2013-05-08 04:17:06
在控制器里写了一个json,
        public ActionResult MeterJson()
{
string json = "{\"total\":1,\"rows\":[{\"productid\":\"FI-SW-01\",\"productname\":\"Koi\",\"unitcost\":10.00,\"status\":\"P\",\"listprice\":36.50,\"attr1\":\"Large\",\"itemid\":\"EST-1\"}]}";
return Content(json.ToString(),"Application/json");
}

在页面中可以显示数据,但是有时候偶尔也会出现显示不出数据以及弹出js错误窗口
--
错误: 无法获取属性“length”的值: 对象为 null 或未定义

页面是这样的
<table id="dataResult" class="easyui-datagrid" title="查询结果" 
data-options="
rownumbers:true,
singleSelect:true,
autoRowHeight:false,
singleSelect:true,
pagination:true,
pageNumber:1,
url:'/Query/MeterJson',
width:1250">
<thead>
<tr>
<th data-options="field:'itemid',width:170">Item ID</th>
<th data-options="field:'productid',width:170">Product</th>
<th data-options="field:'listprice',width:170,align:'right'">List Price</th>
<th data-options="field:'unitcost',width:170,align:'right'">Unit Cost</th>
<th data-options="field:'attr1',width:170">Attribute</th>
<th data-options="field:'status',width:170,align:'center'">Status</th>
</tr>
</thead>
</table>


网上也难以找到类似的问题,希望各位能给我一个解决方法
...全文
313 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
aSD_F123 2014-09-25
  • 打赏
  • 举报
回复
我也是这个问题,请问现在又更好的方法解决吗?
咻呶呶氏 2013-05-09
  • 打赏
  • 举报
回复
--之前看到有人做出的说明,但是怎么把每个域设定为""呢。 原文: 如果返回的数据为空,则在IE浏览器下,页面会有Bug。我的解决办法是,把每个域设为"",这样在页面上就会出现一行空内容的数据。
咻呶呶氏 2013-05-09
  • 打赏
  • 举报
回复
引用 4 楼 showbo 的回复:
firebug或者chrome的开发人员工具监视下报错时返回的数据格式是不是错的罗,有些时候服务器或者浏览器掉链子的事也是有的。。
在chrome中不会出错,这个错误只出现在IE……
Go 旅城通票 2013-05-08
  • 打赏
  • 举报
回复
firebug或者chrome的开发人员工具监视下报错时返回的数据格式是不是错的罗,有些时候服务器或者浏览器掉链子的事也是有的。。
咻呶呶氏 2013-05-08
  • 打赏
  • 举报
回复
感谢,我也试着写在js中,不过同样的问题还是出现,如果不给他设置分页的话,就不会出现任何异常,但是不分页的话又达不到想要的效果
baixubiao 2013-05-08
  • 打赏
  • 举报
回复
我项目里用的也是easyUI.不过 是全部写到js中了。确保 返回的json格式是正确的。符合 easyUI格式。
<table id="Text"></table>
        $('#DepartmentList').datagrid({
            width: 585,
            height: 350,
            nowrap: false,
            striped: true,
            collapsible: true,
            pageSize: 50,
            url: website + '这是地址',
            sortName: 'Name',
            sortOrder: 'asc',
            remoteSort: false,
            idField: 'F5Key',
            frozenColumns: [[
	                { field: 'ck', checkbox: true }
				]],
            columns: [[
				    { title: '多大', field: 'Name', width: 150, sortable: true },
					{ field: 'ShortName', title: '多大', width: 100, sortable: true },
					{ field: 'Dname', title: '多大', width: 120, sortable: true }
				]],
            pagination: true,
            rownumbers: true
        });
咻呶呶氏 2013-05-08
  • 打赏
  • 举报
回复
这种现象是偶然的,但是也必须避免的

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧