为数据表格绑定数据,得到的json字符串中有对象类型数据该如何取值绑定

提问 已结
2 74
xz
xz 2018-5-16
悬赏:20飞吻
json字符串如下:
{
"code":0,
"msg":"",
"count":7,
"data":[
{
"memoId":1,
"memoContent":"随便",
"beginTime":
{"nanos":0,"time":1526442081000,"minutes":41,"seconds":21,"hours":11,"month":4,"timezoneOffset":-480,"year":118,"day":3,"date":16},
"memoTitle":"出行",
"endTime":
{"nanos":0,"time":1526442081000,"minutes":41,"seconds":21,"hours":11,"month":4,"timezoneOffset":-480,"year":118,"day":3,"date":16},
"userInfo":
{"uid":1,"mail":"543543@qq.com","phone":"15823326301","pwd":"123456","sex":0,"name":"admin"}
}]
}

页面js代码如下:
layui.use('table', function(){
var table = layui.table;

table.render({
elem: '#test'
,url:'memo!loadData'
,page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
layout: ['count', 'prev', 'page', 'next', 'skip','limit'] //自定义分页布局
//,curr: 5 //设定初始在第 5 页
,groups: 1 //只显示 1 个连续页码
,first: false //不显示首页
,last: false //不显示尾页
,limits: [3, 10]
,limit:3
}
,cols: [[
{field:'memoId', title: 'ID', sort: true}
,{field:'memoTitle', title: '标题'}
,{field:'memoContent',title: '内容'}
,{field:'beginTime', title: '开始时间'}
,{field:'userInfo', title: '姓名'}
]]
});
});

beginTime和userInfo都是在json中都是对象,如何绑定对象中的某个值在表格中?
回帖
  • cols: [[
    {field:'memoId', title: 'ID', sort: true}
    ,{field:'memoTitle', title: '标题'}
    ,{field:'memoContent',title: '内容'}
    ,{field:'beginTime', title: '开始时间',templet:function(d){
    var da = new Date(d.beginTime.time);
    console.log(d);
    var dformat = [ da.getFullYear(), da.getMonth() + 1, da.getDate() ].join('-')
    + ' ' + [ da.getHours(), da.getMinutes(), da.getSeconds() ].join(':');
    return dformat ;
    }}
    ,{field:'userInfo', title: '姓名',templet:function(d){
    return d.userInfo.name;

    }}
    ]],
    0 回复
  • xz
    2018-5-16
    @自在唯我 太感谢了,我是这样处理的
    {field:'name', title: '姓名',templet:'<div>{{d.userInfo.name}}</div>'}
    贴出来大家共勉
    0 回复