javascript - Sencha 触摸 : how to get config from tpl?

标签 javascript sencha-touch sencha-touch-2

通过 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>'
    }
});

这是我的 View 实现:

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

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

有什么解决方案可以实现这一点吗?

最佳答案

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

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

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

关于javascript - Sencha 触摸 : how to get config from tpl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20332156/

相关文章:

javascript - 在访问者访问的每个网页上叠加一个框架?

sencha-touch - Sencha Cmd V3 测试版

extjs - sencha 创建 jsb -a ./app.html -p ./app.jsb3

store - 从 Sencha Touch 2 中的商店加载轮播?

javascript - Sencha touch 2 native 版本未加载

javascript - Ext.dom 未定义 Sencha Touch

javascript - D3 : Detect mouse wheel event through overlaid SVG

JavaScript 函数默认参数 - 奇怪的行为

javascript - 从对象数组中,如何获取该对象值与变量匹配的对象值?

javascript - Phone gap 3.0 + sencha touch 在设备浏览器中打开 url