簡體   English   中英

yui datatable列點表示法什么都不顯示

[英]yui datatable column dot notation displays nothing

YUI DataTable不顯示'dot.notation'鍵的值(盡管似乎有一個奇怪的技巧可以起作用)。 解決此問題的最佳方法是什么? 我想要一個“正確”的答案,而不是當前的答案,我可以將嵌套的對象弄平並保留嵌套的對象(必須同時存在這兩個對象才能正常工作)。

示例數據(由於奇怪的復制技巧,第三個數據起作用)

var table = new Y.DataTable({
    columns: ['key', 'dot.notation'],
    data: [{
        // broken
        key: 'value',
        'dot.notation': 5
    }, {
        // broken
        key: 'value',
        dot: {
            notation: 5
        }
    }, {
        // displays
        key: 'value',
        'dot.notation': 5,
        dot: {
            notation: 5
        }
    }]
});

http://jsfiddle.net/dirkraft/ERk2d/

使用DataSchema是處理此問題的正確方法。 我相信,虛線鍵版本曾經可以使用,但是隨后版本3.5中的更改停止了該功能

YUI().use('datatable', 'datasource','datasource-jsonschema', function (Y) {

    var ds = new Y.DataSource.Local({
        source: [{
            // broken
            key: 'value',
            'dot.notation': 5
        }, {
            // broken
            key: 'value',
            dot: {
                notation: 5
            }
        }, {
            // displays
            key: 'value',
            'dot.notation': 5,
            dot: {
                notation: 5
            }
        }]
    });

    ds.plug({fn: Y.Plugin.DataSourceJSONSchema, cfg: {
    schema: {
        resultFields: [
            "key",
            {
                key:'foo',
                locator:'dot.notation'
            }
        ]
    }
}});

    var table = new Y.DataTable({
        columns: ['key', 'foo'],
        caption: 'Better Now'
    });
    table.plug(Y.Plugin.DataTableDataSource, {
        datasource: ds
    });
    table.render('#lolol');
    table.datasource.load();

});

http://jsfiddle.net/ERk2d/3/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM