我有一个json:
[{"name":"AA","age":"19","sex":"1","add":"yy","phone":"12345"},
{"name":"BB","age":"20","sex":"0","add":"yy","phone":"43224"},
{"name":"CC","age":"11","sex":"1","add":"yy","phone":"67863"},]
我希望动手只加载名称,年龄,但我不知道如何:(
我想我应该创建一个只有name和age =>的新对象。加载到掌上电脑。我能这样做吗?
任何人都可以帮助我吗?非常感谢你:D
答案 0 :(得分:0)
有几种方法可以做到这一点。您可以按照您最初建议的方式执行此操作,并修改您的JSON对象以仅返回这些字段。或者,你可以这样做:
var data = [
{"name":"AA","age":"19","sex":"1","add":"yy","phone":"12345"},
{"name":"BB","age":"20","sex":"0","add":"yy","phone":"43224"},
{"name":"CC","age":"11","sex":"1","add":"yy","phone":"67863"}
];
var hot = new Handsontable(container, {
...
data: data,
colHeaders: ['Name', 'Age'],
columns: [
{data: 'name'},
{data: 'age'}
],
...
});
使用上面示例中的colHeaders
和columns
选项可让您更灵活地使用前端数据。 :)