Search code examples
javascriptextjssencha-touch-2

sencha can't fire my label show event in controller


i encounter a problem ,beacuse i can't fire my controller function in my view as it's just a alert demo.

my controller:

Ext.define('ylp2p.controller.viewdata',{
    extend: 'Ext.app.Controller',
    config: {
        control: {
            viewlabel: {
                show: 'viewlabelFn'
            }
        },        
        refs: {
            viewlabel: 'label[id=datalabel]',
        }
    },    
    viewlabelFn: function(){
        alert('painted');
    }
});

my view:

Ext.define('ylp2p.view.Main', {
    extend: 'Ext.tab.Panel',
    xtype: 'main',
    requires: [
        'Ext.TitleBar',
        'Ext.carousel.Carousel',
        'ylp2p.store.datainterests',
    ],
    config: {
        fullscreen: true,
        tabBarPosition: 'bottom',
        scrollable: 'vertical',
        items: [
            {
                title: '首页',
                iconCls: 'home',
                styleHtmlContent: true,
                scrollable: true,
                layout: 'card',
                items:  [
                {
                    docked: 'top',
                    xtype: 'titlebar',
                    title: 'ylp2p'
                },
                {
                    xtype: 'container',
                    layout: 'vbox',
                    items:[
                        {
                            xtype: 'carousel',
                            height: 300,
                            items: [
                            {
                                html: 'html1',
                                style: 'background-color:#5E99CC'
                            },
                            {
                                html: 'html2',
                                style: 'background-color: #759E60'
                            },
                            {
                                html: 'html3',
                            }
                            ]
                        },//end carousel
                        {
                            xtype: 'label',
                            id: 'datalabel',
                            //tpl:  '{store.get("data")},{store.get("earn")}',
                            store: 'interestsdata',
                            //tpl: ['总投资:{data},盈利:{earn}'],
                            html: 'hello',
                            flex: 1,
                        }//end label
                    ]
                }
                ]//end items
            },
            {
                title: '融资',
                iconCls: 'locate',
                //xtype: 'makemoney'
            },
            {
                title: '理财',
                iconCls: 'action',
                //xtype: 'money'
            },
            {
                title: '账户',
                iconCls: 'user',
                //xtype: 'user'
            },
            {
                title: '更多',
                iconCls: 'more',
                //xtype: 'more'
            }
        ]
    }
});

Solution

  • Try

    {
        xtype: 'label',
        itemId: 'datalabel',
        //tpl:  '{store.get("data")},{store.get("earn")}',
        store: 'interestsdata',
        //tpl: ['总投资:{data},盈利:{earn}'],
        html: 'hello',
        flex: 1,
    }
    

    and select like this

    Ext.define('ylp2p.controller.viewdata',{
        extend: 'Ext.app.Controller',
        config: {
            control: {
                viewlabel: {
                    show: 'viewlabelFn'
                }
            },        
            refs: {
                viewlabel: '#datalabel',
            }
        },    
        viewlabelFn: function(){
            alert('painted');
        },
    
        launch: function() {
            this.getViewlabel().show();
        }
    });