我有一个由itemid定义的组件如何在控制器中获取它

时间:2015-09-09 03:03:18

标签: javascript extjs sencha-touch-2

我是sencha的新人。我总是使用id来定义我的组件。但现在我想把它改成itemid。我发现Ext.getcmp(' id')不起作用。当我使用Ext.componentquery.query(' itemid')时,chrome中的控制台说Ext.componentquery不是一个函数。我该怎么办?

我的观看代码:

Ext.define('ylp2p.view.Main', {
extend: 'Ext.tab.Panel',
xtype: 'main',
requires: [
    'Ext.TitleBar',
    'Ext.carousel.Carousel',
    'ylp2p.store.datainterests',      
    'Ext.Label',
    'Ext.List'
],
config: {
    fullscreen: true,
    tabBarPosition: 'bottom',
    scrollable: 'vertical',

    items: [
        {
            title: '首页',
            iconCls: 'home',

            styleHtmlContent: true,
            //true to automatically style the HTML inside the content target of this component (body for panels).
            scrollable: true,
            layout: 'card',
            items:  [
            {
                docked: 'top',
                xtype: 'titlebar',
                title: 'ylp2p'
            },
            {
                xtype: 'container',
                layout: 'vbox',
                items:[
                    {
                        xtype: 'label',
                        itemId: 'datalabel',---------this component is what i want
                        height: 50,
                        store: 'datainterests',
                        tpl: '金额:{data},利息:{earn}',
                    }//end label
                ]
            }
            ]//end items
        }
    ]
},//end config

//end listeners
});

我的控制器代码:

Ext.define('ylp2p.controller.viewdata',{
extend: 'Ext.app.Controller',

launch: function(){
    console.log('hello ! here is controller launch function');
    var storeId = Ext.create('ylp2p.store.datainterests');
    storeId.load({
        callback: function(records, operation, success){
            Ext.each(records, function(record) {               
                Ext.ComponentQuery.query("main > datalabel").setData({----it cant work . why?
                    data : record.get('data'),
                    earn : record.get('earn')
                });
            });
        }
    });
}
});

控制台错误说:

Uncaught TypeError: Ext.ComponentQuery.query(...).setData is not a function

2 个答案:

答案 0 :(得分:1)

我明白了

var label  = Ext.ComponentQuery.query('main #datalabel')[0];
label.setData({
  data : record.get('data'),
  earn : record.get('earn')
});

答案 1 :(得分:0)

使用此功能。

var label  = Ext.ComponentQuery.query('main #datalabel');  -- check on console label should not undefined
label.tpl.updateData -- you will find methods with tpl