sencha在其他视图中触摸变量

时间:2011-11-14 15:59:39

标签: sencha-touch extjs

我有一个.js文件,其中显示了一个池列表。当我选择一行时,我将所选行的poolid存储在一个变量中(这很好)。 选择行后,将打开另一个视图,您可以在其中查看属于池的guest虚拟机。但为了表明这一点,我需要在此视图中使用其他视图中的poolid变量。但是如何?

//我选择游泳池的视图

Dashboard = new Ext.Application({
name:'Dashboard',
launch: function(){
    var poolId;
    var thePanel = "allPool"
//------------------------------------List with Pool info
    var detailPanel = new Ext.Panel({
        id:'detailPanel',
        layout:'fit',
         items: [{
            fullscreen:true,
            xtype: 'list',
            store: new Ext.data.Store({
                model: 'team',
                getGroupString : function(record) {
                    return record.get('name')[0];
                },
                proxy: new Ext.data.AjaxProxy({
                    url: 'a.php/pool/listPools',
                    method:'post',
                    reader: {
                        type: 'json',
                        root: 'data',
                        totalCount: 'count'
                     }
                })
                ,autoLoad:true 
            }),
            sorters: [{
            property: 'name',
            direction: 'asc'
             }],
            itemTpl:'<font size="4" face="Helvetica, Arial" color="black">{name}</font>',
            grouped: true,
            onItemDisclosure : true,
                  listeners : {
              itemtap : function(record,index,item,e){
                 if (e.getTarget('.x-list-disclosure')) {
                     thePanel = 'guestsofPool';
                     poolId = this.store.data.items[index];
                     Ext.Ajax.request({
                        url : 'a.php/guest/listGuests' , 
                            params : { 
                            poolId: poolId
                            },
                    method: 'POST',
                    success: function (result, request) { 
                        var redirect = "showpool.php";
                        window.location = redirect;

                    },
                    failure: function ( result, request) { 
                        alert(result.responseText);
                    } 
                });
                     //TopPanel.dockedItems.items[0].setTitle('Guests');
                     //outer.setActiveItem(1, { type: 'slide', cover: false, direction: 'right'});
                 } 
                // else { Ext.Msg.alert("Item clicked!");}
               }
             }
        }]
    })

//您应该看到所选POOLID的所有来宾的视图

ListDemo = new Ext.Application({
name: "ListDemo",
launch: function() {

    ListDemo.detailPanel = new Ext.Panel({

        id: 'detailpanel',
        dock: "top",
        items: [{

            fullscreen:true,
            xtype: 'list',

            store: new Ext.data.Store({
                model: 'team',
                getGroupString : function(record) {
                    return record.get('name')[0];
                },   
                proxy: new Ext.data.AjaxProxy({                        
                    url: 'a.php/guest/listGuests',
                    extraParams: {
                        poolId: thepoolid which was selected in the other view 
                    },
                    method:'post',
                    reader: {
                            type: 'json',
                            root: 'data',
                             totalCount: 'count'
                                 }
                }),autoLoad:true 
            }),

            sorters: [{
            property: 'name',
            direction: 'asc'
             }],
            itemTpl:'<font size="4" face="Helvetica, Arial" color="black">{name}</font>',
            grouped: true,
            onItemDisclosure : true,
                  listeners : {
              itemtap : function(record,index,item,e){
                 if (e.getTarget('.x-list-disclosure')) {
                    //Ext.Msg.alert(index);
                    var redirect = 'showpool.php'; 
                    window.location = redirect;
                 } 
                // else { Ext.Msg.alert("Item clicked!");}
               }
             }
        }]
    });

1 个答案:

答案 0 :(得分:0)

我没有耐心去查看您发布的完整代码。但我建议在index.js文件中添加一个变量var selectedPool_id;并在itemTap设置此ID。并在任何需要的地方获取值。

注意:确保文件index.js已添加到您的html文件之前,并添加到正在选择并使用selectedPool_id的文件中。

这是一种解决方法。我欢迎提出建议和改进。