OA问题总结

一、mustache渲染时ajax返回的数据处理

1.ajax返回的是对象,直接用mustache不行。返回的数据如下:

{"1":{"count":"23","status_name":"已立项,待派人","list":[{"name":"济南泉城路万达广场fdsfa","transfer_time":"1天前"},{"name":"济南泉城路万达广场654654","transfer_time":"2天前"},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_time":""},{"name":"测试ddd","transfer_t ... [total: 1498]

2.于是先将数据转换成数组

var result = [];
 var keys = Object.keys(json);
  for (var i = 0, len = keys.length; i < len; i++) {
         result.push(json[keys[i]]);
   }
console.log(result);

3.包装成要传入的数据对象

var ctx = {persons: result};

4.mustache渲染

var dom = Mustache.render(this.tpl, ctx); 
$('#task-pane').append(dom);

你可能感兴趣的:(OA问题总结)