繁体   English   中英

Sencha Touch:如何从TPL获取配置?

[英]Sencha Touch: how to get config from tpl?

使用Sencha Touch,我创建了一个组件来显示我的移动应用程序的表格。

这是我的组件代码:

Ext.define('MyApp.components.table.Table', {
    extend: 'Ext.Container',
    xtype: 'table',

    config: {
    cls: 'myTableCSS',
    scrollable: 'vertical',
    tpl: Ext.create('Ext.XTemplate',
        '<tpl for=".">',
            '<table>',
                '<tr>',
                    '<tpl for="headers">',
                        '<th>{html}</th>',
                    '</tpl>',
                '</tr>',
                '<tpl for="rows">',
                    '<tr class="{[this.config.id]}" >',
                        '<tpl for="columns">',
                                '<td>{html}</td>',
                        '</tpl>',
                    '</tr>',
                '</tpl>',
            '</table>',
        '</tpl>'
    }
});

这是我的视图实现:

xtype: 'table',
id: 'myRedTable',
data: [
    {
        headers: [
            { html: 'firstname' },
            { html: 'lastname' },
            { html: 'age' }
        ],
        rows: [
            {
                columns: [
                    { html: 'John' },
                    { html: 'Smith' },
                    { html: '38' },
                ]
            }
        ]
    }
],

在我的组件中,当我使用{[this.config.id]}我想获取视图实现的ID(即myRedTable ),但是它不起作用。

有什么解决方案可以做到这一点吗?

看来您正确地编写了内联任意代码的语法,但是范围存在问题。 this是指Ext.XTemplate本身的实例,而不是表视图。

您应该尝试另一种方法来获取表实例的引用,例如,在表的定义文件中:

initialize: function(){
    var me = this;
    me.setTpl('Ext.XTemplate',
        // blah blah ...
        // now you can use "me" to refer to your table instance
    )
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM