jQuery MiniUI

标题: dataGrid如何加载已经拼接好的JSON对象。 [打印本页]

作者: lmjavajas    时间: 2012-10-25 14:35:56     标题: dataGrid如何加载已经拼接好的JSON对象。

  var json = "[{\"position\":\"js3\",\"birthday\":\"1987-06-12T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"技术部\",\"position_name\":\"前端工程师\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"54b12a07-1f7d-4616-b3e9-9dcc465a5f33\",\"loginname\":\"13625147852@163.com\",\"dept_id\":\"js\",\"school\":\"南京邮电学院\",\"married\":0,\"email\":null,\"age\":25,\"name\":\"张鹏楠\",\"educational\":\"2\",\"gender\":1,\"salary\":\"3230\"},{\"position\":\"js2\",\"birthday\":\"1985-07-17T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"技术部\",\"position_name\":\"后台工程师\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"20ac24f7-a34c-4f12-89f0-91d65b2ddfa9\",\"loginname\":\"xucc198712@qq.com\",\"dept_id\":\"js\",\"school\":\"南京邮电学院\",\"married\":0,\"email\":\"xucc198712@qq.com\",\"age\":27,\"name\":\"徐承承\",\"educational\":\"2\",\"gender\":2,\"salary\":\"4373\"},{\"position\":\"js3\",\"birthday\":\"1987-10-07T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"技术部\",\"position_name\":\"前端工程师\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"d6fb5410-adde-46a9-9d2b-dee99c64a83d\",\"loginname\":\"xzz@163.com\",\"dept_id\":\"js\",\"school\":\"宁波工程大学\",\"married\":0,\"email\":\"xzz@163.com\",\"age\":25,\"name\":\"谢忠哲\",\"educational\":\"2\",\"gender\":2,\"salary\":\"3860\"},{\"position\":\"rs1\",\"birthday\":\"1978-12-15T00:00:00\",\"educational_name\":\"研究生\",\"remarks\":\"\",\"dept_name\":\"人事部\",\"position_name\":\"人事部经理\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"ac3c3166-e677-45a5-9d1b-da4f09d6fc2a\",\"loginname\":\"zhoulan2010@hotmail.com\",\"dept_id\":\"rs\",\"school\":\"南京理工大学\",\"married\":1,\"email\":\"zhoulan2010@hotmail.com\",\"age\":34,\"name\":\"周兰\",\"educational\":\"3\",\"gender\":2,\"salary\":\"6580\"},{\"position\":\"rs2\",\"birthday\":\"1987-03-17T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"人事部\",\"position_name\":\"人事助理\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"b0171c0f-5064-4975-9f54-ebf28666aca6\",\"loginname\":\"jan3844@gmail.com\",\"dept_id\":\"rs\",\"school\":\"浙江理工大学\",\"married\":0,\"email\":\"jan3844@gmail.com\",\"age\":25,\"name\":\"沈臻妍\",\"educational\":\"2\",\"gender\":2,\"salary\":\"3400\"},{\"position\":\"sc3\",\"birthday\":\"1988-11-18T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"市场销售部\",\"position_name\":\"销售员\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"61a6943f-990e-4169-b6a0-bed9bdc42a5f\",\"loginname\":\"xiaoqian18392342@qq.com\",\"dept_id\":\"sc\",\"school\":\"南京信息工程大学\",\"married\":0,\"email\":\"xiaoqian18392342@qq.com\",\"age\":24,\"name\":\"陈晓倩\",\"educational\":\"2\",\"gender\":2,\"salary\":\"3000\"},{\"position\":\"js2\",\"birthday\":\"1984-11-08T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"技术部\",\"position_name\":\"后台工程师\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"9252b4a2-8000-4b3e-b29a-ac7849163ca2\",\"loginname\":\"djf19830326@qq.com\",\"dept_id\":\"js\",\"school\":\"南京理工大学\",\"married\":1,\"email\":\"djf19830326@qq.com\",\"age\":28,\"name\":\"杜鉴锋\",\"educational\":\"2\",\"gender\":1,\"salary\":\"5300\"},{\"position\":\"sc3\",\"birthday\":\"1988-01-28T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"市场销售部\",\"position_name\":\"销售员\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"7ef2fc41-27b2-4991-9134-189f95d76c42\",\"loginname\":\"hk2006@qq.com\",\"dept_id\":\"sc\",\"school\":\"湖南科技大学\",\"married\":0,\"email\":\"hk2006@qq.com\",\"age\":24,\"name\":\"黄凯\",\"educational\":\"2\",\"gender\":1,\"salary\":\"2900\"},{\"position\":\"sc3\",\"birthday\":\"1987-08-19T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"市场销售部\",\"position_name\":\"销售员\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"a817ca24-ede0-4932-8455-b1e86eb7772d\",\"loginname\":\"wl19861219@163.com\",\"dept_id\":\"sc\",\"school\":\"南京审计学院\",\"married\":0,\"email\":\"wl19861219@163.com\",\"age\":25,\"name\":\"王岚\",\"educational\":\"2\",\"gender\":2,\"salary\":\"3000\"},{\"position\":\"sc1\",\"birthday\":\"1977-06-21T00:00:00\",\"educational_name\":\"本科\",\"remarks\":\"\",\"dept_name\":\"市场销售部\",\"position_name\":\"市场总监\",\"city\":\"\",\"country\":\"\",\"createtime\":\"2000-11-10T01:01:01\",\"id\":\"b4366fb3-fb9c-4244-b3b6-c56de0c70cde\",\"loginname\":\"tangyue@gmail.com\",\"dept_id\":\"sc\",\"school\":\"金陵科技大学\",\"married\":1,\"email\":\"tangyue@gmail.com\",\"age\":35,\"name\":\"唐岳\",\"educational\":\"2\",\"gender\":1,\"salary\":\"6300\"}]";
  var jsonD = "(" + json + ")"; // 用括号将json字符串括起来
  var jsons = eval(jsonD);
  mini.parse();
  //mini.get("datagrid1").setUrl("../data/datagrid.txt");
    //mini.get("datagrid1").loadData(jsons);
  var grid = mini.get("datagrid1");
     //grid.setData(jsons);
     //grid.loadData(jsons);
  grid.load();
  //grid.sortBy("createtime", "desc");
  grid.groupBy ( "dept_name", "desc" );
我现在已经有一个JSON对象了,自己拼接的,在加载的时候我使用的是loadDta()方法以及setData方法都用了,在页面上数据能加载出来但是总会弹出一个UNDEFINED。如果我把JSON字符串放在文datagrid.txt文件,以URL的方式传送页面是正常的。我如何将自己拼接的JSON对象展正常展现?

作者: factory    时间: 2012-10-25 14:40:32

var data = mini.decode(json);
grid.setData(data);
作者: lmjavajas    时间: 2012-10-25 14:50:06

factory 发表于 2012-10-25 14:40
var data = mini.decode(json);
grid.setData(data);

,我刚刚使用了你说的方法依旧会报错
作者: lmjavajas    时间: 2012-10-25 14:51:33

lmjavajas 发表于 2012-10-25 14:50
,我刚刚使用了你说的方法依旧会报错


作者: factory    时间: 2012-10-25 15:02:51

lmjavajas 发表于 2012-10-25 14:51

图看不到,报的什么错。
我用上面你的数据,
var data = mini.decode(json);
grid.setData(data);
是可以加载数据的
作者: qinskys    时间: 2012-10-25 15:07:34

这些数据是真的假的,就这样暴露出来可以吗
作者: factory    时间: 2012-10-25 15:10:10

qinskys 发表于 2012-10-25 15:07
这些数据是真的假的,就这样暴露出来可以吗

官网的数据都是捏造的。
你刚才的图挂了,看不到,你说下你报的什么错吧

作者: lmjavajas    时间: 2012-10-25 15:12:53

factory 发表于 2012-10-25 15:02
图看不到,报的什么错。
我用上面你的数据,
var data = mini.decode(json);

可以了,刚刚我太粗心了,将对象mini.parse();定义误删。谢谢!




欢迎光临 jQuery MiniUI (http://miniui.com/discuss/) Powered by Discuz! X2