0

JSFiddleで作業する例があります。

KnockoutJS バインディングを使用して作成する必要がある YUI DataTable によって消費される JSON の一部があります。私は 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();

}); </p>

これは KnockoutJS 入札を使用して行うことができますか? KnockoutJS バインディングを使用して HTML テーブルを適切に作成できることは知っていますが、YUI の部分は扱いにくいと思います。助けてください。

4

2 に答える 2

0

表のセルにいくつかのデータバインド属性を追加する必要があると思います。YUI テーブルを使用すると、テンプレートを使用して TD 要素の作成をカスタマイズできます。詳細については、YUI のドキュメントを参照してください

于 2012-09-12T02:07:18.690 に答える
0

A custom binding helps resolve this problem. I can put the datatable creation code in the custom binding so that it will create he table on the markup from which the binding was called. Cool.

于 2012-11-20T12:03:09.317 に答える