Próbuję wyświetlić następujący obiekt JSON przy użyciu YUI DataTable. Udało mi się pokazać LastName, firstName, startDate, employeeCode, employeeStatus w YUI DataTable. Ale nie mogłem pokazać wartości w wewnętrznym przedmiocie. W zestawie kolumn próbowałem user.userId i jest wyświetlany jako {wartość} w DataTable.Wyświetl obiekt JSON w YUI 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,
},
{
...
}
]
Oto kod 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>
jest coś nie w porządku z tym fragmencie kodu? Jak wyświetlić wartość user.userId w DataTable?
Uwaga: JSON jest generowana z Jackson i stosowania został opracowany w gae/J
UPDATE:
że stosowane źródło danych zgodnie z sugestią @Luke. Tym razem dostałem pusty DataTable z tylko nagłówkami. Oto fragment kodu.
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();
});
Próbowałem użyć źródła danych, ale teraz wydaje się, że YUI wysyła złe żądanie do serwera. Oto adres URL, który otrzymałem z konsoli firebug: http: // localhost: 8080/ExampleApp/Employee/AjaxListundefined & callback = YUI.Env.DataSource.callbacks.yui_3_4_0_1_1316763699238_127 Prawidłowy adres URL to http: // localhost: 8080/ExampleApp/Employee/AjaxList – libregeek
Zignoruj powyższy komentarz. Rozwiązałem ten problem, dodając "?" na końcu źródłowego adresu URL. Ale nadal dane nie są objaśniane w datatable. Widzę dane JSON w konsoli firebug. – libregeek
Mam zaktualizowane pytanie ze skryptem przy użyciu datasource-arrayschema. Wierzę, że odpowiedź, którą otrzymuję, jest tablicą i nie mogłem zidentyfikować resultListLocator dla źródła danych-jsonschema – libregeek