我的模板模型破坏了togglePanel()?

时间:2014-12-07 01:44:04

标签: polymer

为什么t.model = model会破坏我的p.togglePanel()

        var t = document.querySelector('template')
        t.addEventListener('template-bound', function() {
            t.model = model //<= this breaks my togglePanel?
            var p = document.querySelector('core-drawer-panel')
            p.togglePanel() //<= does not work see above
        })

我的模型看起来像这样,需要配置我的聚合物表。请注意,表本身有效,其togglePanel()停止工作。

        var data = [
            {fruit: 'apple', alice: 4, bill: 10, casey: 2, average: 5.3, total: 16 },
            {fruit: 'banana', alice: 0, bill: 4, casey: 0, average: 1.3, total: 4 },
            {fruit: 'grape', alice: 2, bill: 3, casey: 5, average: 3.3, total: 10 },
            {fruit: 'pear', alice: 4, bill: 2, casey: 8, average: 4.6, total: 14 },
            {fruit: 'strawberry', alice: 0, bill: 14, casey: 1, average: 5, total: 15 }
        ]

        var columns = [
            {name:'fruit', cellTemplate: 'fruitsTemplate'},
            {name:'alice'},
            {name:'bill'},
            {name:'casey'},
            {name:'average'},
            {name:'total'}
        ]

        var model = {
            data: data,
            columns: columns
        }

1 个答案:

答案 0 :(得分:0)

修正了它,我覆盖了太多模特的东西。

    var t = document.querySelector('template')
    t.addEventListener('template-bound', function() {
        t.model.data = data
        t.model.columns = columns
        var p = document.querySelector('core-drawer-panel')
        p.togglePanel()
    })

如果每个web组件使用相同的模型进行自我配置,这可能是一个设计问题?