简体   繁体   English

Sencha touch 2.0和iPhone:向面板动态添加元素和setActiveItem

[英]Sencha touch 2.0 and iphone : add element to panel dynamically and setActiveItem

I am trying to add dinamically a panel item to a main panel with a card layout which has initially one panel in it. 我试图将一个面板项目动态地添加到具有卡布局的主面板中,该布局最初具有一个面板。 After one event (a tap) i build dinamically a new panel and I add it to the main panel, after this i try to set the new panel item like the active one via setActiveItem 在一个事件(轻按)之后,我会动态地建立一个新面板并将其添加到主面板中,在此之后,我尝试通过setActiveItem将新面板项设置为活动面板,例如活动面板

Things work ok on Android but not on iphone. 在Android上一切正常,但在iPhone上却无法正常工作。

Exactly i have this app.js: 确实我有这个app.js:

Ext.Loader.setConfig({enabled: true});
Ext.setup({
viewport: {
    autoMaximize: false
},
onReady: function() {
    var app = new Ext.Application({
        name: 'rpc',
        appFolder: 'app',           
        controllers: ['Home'],
        autoCreateViewport: false,
        launch: function () {
            Ext.create('Ext.Panel',{
                fullscreen: true,           
                layout: {
                    type : 'card',
                    animation:{
                        type:'slide'
                        ,duration :3000
                    }
                },
                defaults: {     /*definisce le caratteristiche di default degli elementi contenuti..??*/
                    flex: 1
                },
                items:[{
                    title: 'Compose',
                    xtype: 'griglia'
                }]
            });
        }
    });
}
});

In a controller i have 在控制器中,我有

            .....
        .....
        var grigliaPan=button.up('griglia');
        var mainPan=grigliaPan.up('panel');

        var html=
            '<img src="img/'+segnoScelto+'_big.png" />'
            +'<h1>'+segnoScelto+'</h1>'
            +'<p>'+previsione+'</p>'
            +'</br></br>';
        if (typeof mainPan.getComponent(1) == 'undefined'){
                        var previsioPan = Ext.widget('previsio');
                        previsioPan.setHtml(html);

                        //here i create a button for going home panel
                        var backButton=new Ext.Button({
                            ui  : 'decline',
                            alias: 'widget.backbutton',
                            text: 'Home Page',
                            width : 150,
                            height:100
                        })

                        previsioPan.add(backButton);
                        var it=mainPan.getItems();
                        alert (it['keys']);     //this prints : ext-griglia-1
                        mainPan.add(previsioPan);
                        var it=mainPan.getItems();
                        alert (it['keys']);     //this prints : ext-griglia-1,ext-previsio-1
                        //
        }
        mainPan.getLayout().setAnimation({type: 'slide', direction: 'left', duration:1000});
        //mainPan.setActiveItem(1);
        var pree=mainPan.getAt(1);
        //pree.show();
        //mainPan.setActiveItemm(pree);
        mainPan.setActiveItem('ext-previsio-1');

The three form of setActiveItem() are ok for Android and falls with iPhone. setActiveItem()的三种形式适用于Android,适用于iPhone。 Can somebody please show me what is the right way to set the new active item added dinamically on the iphone ? 有人可以告诉我设置在iPhone上动态添加的新活动项目的正确方法是什么吗?

The problem should not be with the add() function cause i can see the new item via the getItems() added in main panel after the add(). 问题不应该与add()函数有关,因为我可以通过在add()之后在主面板中添加的getItems()看到新项目。

by following code you can understand that thisCell is added later after creation of thisRow. 通过以下代码,您可以了解thisCell是在创建thisRow之后添加的。

var thisRow = new Ext.Panel({ 
                 layout: { type: 'hbox', align: 'stretch', pack: 'center' },
                 id: 'row' + (rowCount + 1), 
                 defaults: { flex: 1 } 
              });

        // Now we need to add the cells to the above Panel:
var thisCell = new Ext.Panel({
             cls: 'dashboardButton',
                 layout: { type: 'vbox', align: 'center', pack: 'center' },
         items: [{
                      xtype: 'image',
                      src: 'some image url',
                      height: '70px',
                      width: '100px',
                 }]
               });
thisRow.add(thisCell);

hope this will help you to achieve your desired output... 希望这将帮助您实现所需的输出...

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

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