sencha 触摸其他视图中的变量

发布于 2024-12-15 13:57:47 字数 4215 浏览 1 评论 0原文

我有一个 .js 文件,其中显示池列表。当我选择一行时,我将所选行的 poolid 存储在变量中(这很好用)。 选择一行后,会打开另一个视图,您可以在其中看到属于泳池的客人。但为了显示这一点,我需要使用此视图中另一个视图中的 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!");}
               }
             }
        }]
    })

//您应该看到所选池ID的所有客人的视图

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!");}
               }
             }
        }]
    });

i have a .js file where i show a list of pools. And when i select a row i store the poolid of the selected row in a variable(this works fine).
And after you have selected a row an other view opens where you can see the guests which belongs to the pool. BUT to show this i need to use the poolid variable from the other view in this view. But how?

//The view where i select a pool

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!");}
               }
             }
        }]
    })

//The view where you should see all the guests of the selected 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!");}
               }
             }
        }]
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦与时光遇 2024-12-22 13:57:47

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

注意:请确保在选择和使用 selectedPool_id 的文件之前将文件 index.js 添加到您的 html 文件中。

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

I din't had patience to go through the complete code you posted. But what I'd suggest is have a variable in index.js file say var selectedPool_id; and in the itemTap set this id. and fetch the value wherever you need it.

NOTE: mak sure that the file index.js is added to your html file prior to the files that are selecting and usent he selectedPool_id.

This was a workaround. I welcome suggestions and improvements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文