我有一個工作在JSFiddle的例子。YUI DataTable使用KnockoutJS綁定
它有一塊JSON數據表所使用的JSON,我需要使用KnockoutJS綁定來創建它。我對KnockoutJS相當陌生,並想知道如何做到這一點。
表應的標記下創建 -
<div class="yui3-skin-sam" id="datatable"></div>
的代碼變爲如下 -
YUI().use('datatable', 'datasource-local', 'datasource-jsonschema',function(Y){
var data = {"generations": [{
"type": "Modern",
"showName": "The Modern Generation",
"imgURI": "file:/D:/projectGen.png",
"relations": {
"father": {
"age": "49",
"firstName": "George",
"lastName": "Mathews",
"priority": "1",
"profession": "Service"
},
"mother": {
"age": "47",
"firstName": "Susan",
"lastName": "Aldrin",
"priority": "2",
"profession": "Home-Maker"
},
"brother": {
"age": "28",
"firstName": "Martin",
"lastName": "Mathews J",
"priority": "3",
"profession": "Engineer"
},
"sister": {
"age": "23",
"firstName": "Laura",
"lastName": "Mathews J",
"priority": "4",
"profession": "Fashion Model"
},
"aunt": {
"age": "50",
"firstName": "Sally",
"lastName": "Bekkers",
"priority": "5",
"profession": "Singer"
}
}
}]
};
var localDataSource = new Y.DataSource.Local({source:data});
var dynamicColumns = Y.Object.keys(data.generations[0].relations);
var config = {
schema: {
resultListLocator: 'generations',
resultFields: [{key:'showName'}]
}
};
Y.Array.each(dynamicColumns,function(key){
config.schema.resultFields.push({
key: key,
locator: "relations."+key + ".firstName"
});
});
var jsonSchema = localDataSource.plug(Y.Plugin.DataSourceJSONSchema, config);
console.log(config.schema.resultFields);
var table = new Y.DataTable({
columns: config.schema.resultFields
});
table.plug(Y.Plugin.DataTableDataSource, {
datasource: localDataSource
});
table.render('#datatable');
table.datasource.load();
});
這可以使用KnockoutJS出價完成嗎?我知道使用KnockoutJS綁定可以很好地創建HTML表格,但我發現YUI部分很棘手。請幫忙。
有沒有辦法使用Knockout綁定來做到這一點?如何使用'html'綁定到這個問題? 我閱讀了你建議的YUI文檔,但似乎並不適用於問題的上下文。 – StackOverflow
你是什麼意思「使用敲除綁定」?這不是什麼數據綁定屬性? – klamping