0
我想模仿使用KnockoutJS数据绑定创建YUI3数据表。 比方说,我有以下的JSON字符串 -如何为使用JSON数据的YUI DataTable创建KnockoutJS模板?
{ “@lang”: “EN-US”,
"cartItem": {
"@lang": "en-US",
"cartId": "14",
"items": [
{
"@lang": "en-US",
"id": "5",
"name": "global/network/main",
"propertyURL": "mail.yahoo.com",
"rootPropertyName": "All Other",
"spaceId": "2023407535"
},
{
"@lang": "en-US",
"id": "5",
"name": "global/network/main",
"propertyURL": "mail.yahoo.com",
"rootPropertyName": "All Other",
"spaceId": "2023407535"
}
]
},
"status": {
"@lang": "en-US",
"message": "",
"status": "success"
}
}
而且我用下面的代码来创建YUI数据表消耗上述JSON - 。
YUI()的使用( “数据表”, “数据表-数据源”, “数据源本地”, “数据源-jsonschema”,函数(Y){
var jsonString = Y.one("#jsondata").getHTML();
var dtsource = new Y.DataSource.Local({source:jsonString});
dtsource.plug(Y.Plugin.DataSourceJSONSchema, {
4schema: {
resultListLocator: "cartItem.items",
resultFields: [
// Re-map the "id" member to "rid" ...
{ key:"rid", locator:"id"},
"name", "propertyURL", "rootPropertyName"
]
}
});
var colums = ["rid", "name", "propertyURL", "rootPropertyName"];
var dtable = new Y.DataTable({
columns: colums,
summary:"Shopping cart items",
caption:"Table with JSON data from api"});
dtable.plug(Y.Plugin.DataTableDataSource,{
datasource:dtsource
});
dtable.render("#jsonapi-datatable");
dtable.datasource.load({request:"&id=14"});
});
如何为上面的代码创建一个KnockoutJS模板?
在菲德尔 - http://jsfiddle.net/pPY7K/6/