我想使用YUI DataTable顯示下面的JSON對象。我能夠在YUI DataTable中成功顯示lastName,firstName,startDate,employeeCode,employeeStatus。但是我無法在內部對象中顯示值。在列集中,我嘗試了user.userId,它在DataTable中顯示爲{value}。在YUI中顯示JSON對象Datatable
[
{
"lastName": "MyLastName",
"firstName": "MyFirstName",
"startDate": "11-11-11",
"employeeCode": "124",
"employeeStatus": "Permanent",
"user": {
"key": {
"name": null,
"parent": {
"name": null,
"parent": null,
"id": 855,
"namespace": "",
"complete": true,
"kind": "Employee"
},
"id": 856,
"namespace": "",
"complete": true,
"kind": "Users"
},
"salt": null,
"userId": "[email protected]",
"status": true,
},
{
...
}
]
下面是Javascript代碼:
<script type="text/javascript">
YUI().use("jsonp", 'sortable', 'json-parse', 'datatable', "datatable-sort", "io", "node", function(Y) {
var nestedCols = [
{key : "employeeCode",label : "Employee Code", sortable:true},
{key : "firstName", label : "First Name",sortable: true},
{key : "lastName", label : "Last Name", sortable:true},
{key : "user.userId", label : "Email Id"},
];
Y.io('/Employee/AjaxList', {
on : {
success : function(tx, r) {
var data = Y.JSON.parse(r.responseText);
var table = new Y.DataTable.Base({
columnset : nestedCols,
recordset : data,
}).plug(Y.Plugin.DataTableSort);
table.render("#empTable");
}
}
});
});
</script>
有什麼不對的代碼片段?如何在DataTable中顯示user.userId的值?
注意:在使用傑克遜生成的JSON和應用程序在GAE/J開發
UPDATE:
我使用的DataSource通過@Luke建議以下。這一次我得到一個只有頭文件的空DataTable。這是代碼片段。
YUI().use("datasource-get", "datatable-base", "datatable-datasource","datasource-arrayschema", function (Y) {
var url = "/Employee/AjaxList?";
var dataSource, table;
dataSource = new Y.DataSource.Get({ source: url });
dataSource.plug(Y.Plugin.DataSourceArraySchema, {
schema: {
resultFields: ["firstName", "lastName"]
}
});
var cols = ["firstName", "lastName"];
table = new Y.DataTable.Base({
columnset: cols,
});
table.plug(Y.Plugin.DataTableDataSource, { datasource: dataSource });
table.render("#empTable");
table.datasource.load();
});
我嘗試使用數據源,但現在看來YUI發送錯誤的請求到服務器。這裏是我從螢火蟲控制檯得到的URL:http:// localhost:8080/ExampleApp/Employee/AjaxListundefined&callback = YUI.Env.DataSource.callbacks.yui_3_4_0_1_1316763699238_127正確的網址是http:// localhost:8080/ExampleApp/Employee/AjaxList – libregeek
請忽略上述評論,我通過追加'?'來解決此問題。在源URL的末尾。但數據仍然沒有在數據表中出現。我可以在Firebug控制檯中看到JSON數據。 – libregeek
我用腳本使用datasource-arrayschema更新了問題。我相信我得到的響應是一個數組,我無法識別datasource-jsonschema的resultListLocator – libregeek