Sencha触摸导航问题在后退按钮

时间:2013-11-10 19:51:50

标签: extjs sencha-touch sencha-touch-2 sencha-architect sencha-touch-2.1

我试图在sencha touch中创建导航。我遇到了一个我无法弄清楚的情况。请帮我弄清楚当我按下按钮时事件监听器不工作的原因。

我创建了一个主容器,其中包含一个单独的位置,用于动态添加面板。

后退和下一个按钮位于主视图中的另一个面板中。

当我的添加功能触发时,它会添加面板的功能并且可以正常工作一次。但是,当我浏览后退按钮时,功能无效,即'piccsClicked','cvcsClicked';图像更改的位置。还有一些其他功能

请帮助我理解问题和解决方案。

我的猜测是因为当我按下按钮时我正在创建一个面板     xtype:“”+ newPanel +“” 它创建了一个全新的面板,功能不适用于此。请帮我解决这个问题。

以下是代码

 var current = 1;
 var myPanel = new Array("panelOne", "panelOneP", "panelTwoP", "panelThreeP", "panelFourP", "panelFiveP", "panelOneC", "panelTwoC", "panelThreeC", "panelFourCVC", "panelFiveC", "panelSixCGraph", "panelSixPGraph");

 Ext.define("myApp.controller.MainController", {
     extend: "Ext.app.Controller",

     config: {
         refs: {
             main: '#main',
             backButton: '#backButton',
             nextButton: '#nextButton',
             panelArea: '#panelArea', //this panel is in main view along with some other panels, among the other panels there is a panel which contains the back and next buttons
             panelOne: '#panelOne', // these are the views extending Ext.Panel
             panelOneP: '#panelOneP',
             panelTwoP '#panelTwoP',
             panelThreeP: '#panelThreeP',
             panelFourP: '#panelFourP',
             panelFiveP: '#panelFiveP',
             panelSixPGraph: '#panelSixPGraph',
             panelOneC: '#panelOneC',
             panelTwoC: '#panelTwoC',
             panelThreeC: '#panelThreeC',
             panelFourC: '#panelFourC',
             panelFiveC: '#panelFiveC',
             panelSixCGraph: '#panelSixCGraph',
             piccs: '#piccs', // these two are images in the panelOne
             cVCs: '#CVCs',
         },

         control: {
             cVCs: {
                 tap: 'cvcsClicked'
             },
             piccs: {
                 tap: 'piccsClicked'
             },
             backButton: {
                 tap: 'navigateBack'
             },
             nextButton: {
                 tap: 'navigateNext'
             },
         },
     },

     navigateBack: function () {
         current = current - 1;
         this.addPanel(myPanel[current]);
     },

     navigateNext: function () {
         current = current + 1;
         this.addPanel(myPanel[current]);
     },

     addPanel: function (newPanel) {

         this.getPanelArea().removeAt(0);

         }
         var myNewPanel = Ext.create('Ext.Panel', {
             items: [{
                 xtype: "" + newPanel + ""  // every view is given ID exactly as in the array
             }]
         });
         this.getPanelArea().add(myNewPanel);
     },

     piccsClicked: function () {
         var current = this.getPiccs().getSrc();
         if (current == 'resources/images/checkBoxUnchecked.jpg') {
             this.getPiccs().setSrc('resources/images/checkBoxChecked.jpg');
         } else {
             this.getPiccs().setSrc('resources/images/checkBoxUnchecked.jpg');
         }
     },

     cvcsClicked: function () {
         var current = this.getCVCs().getSrc();
         if (current == 'resources/images/checkBoxUnchecked.jpg') {
             this.getCVCs().setSrc('resources/images/checkBoxChecked.jpg');
         } else {
             this.getCVCs().setSrc('resources/images/checkBoxUnchecked.jpg');
         }
     },

 });

2 个答案:

答案 0 :(得分:1)

我遇到了同样的麻烦。我通过这样做解决了这个问题:

  1. 在您的控制器中,创建一个新的ref

    backToNav: 'myNavXtypeName button[text=Back]'
    
  2. 在同一个控制器中,将ref链接到control

    backToNav: {
            tap: 'backToNav'
    }
    
  3. 最后创建实现导航视图弹出功能的控制器方法。

    backToNav: function() {
            Ext.getCmp('myNavXtypeName').pop()
    }
    
  4. 完成。 Read more about refs and controls here

答案 1 :(得分:-1)

在您放置逗号,的位置时要小心,并检查所有内容是否已正确关闭{,并且}括号正确。

基本上,您不应在括号,}之前放置任何] 就像你最后做的那样:

    },
});

'#CVCs',之后

    cVCs: '#CVCs',
},

您确定要将},放在this.getPanelArea().add(myNewPanel);之后吗?

    this.getPanelArea().add(myNewPanel);
},

这将关闭您的控制器定义,但您还有两个函数piccsClickedcvcsClicked应该在结束},之前完成。

此外,关闭控制器应该是});而不是}, (可能是偶然留在那里)

试试这个:

var current = 1;
var myPanel = new Array("panelOne", "panelOneP", "panelTwoP", "panelThreeP", "panelFourP", "panelFiveP", "panelOneC", "panelTwoC", "panelThreeC", "panelFourCVC", "panelFiveC", "panelSixCGraph", "panelSixPGraph");

Ext.define("myApp.controller.MainController", {
    extend: "Ext.app.Controller",

    config: {
        refs: {
            main: '#main',
            backButton: '#backButton',
            nextButton: '#nextButton',
            panelArea: '#panelArea', //this panel is in main view along with some other panels, among the other panels there is a panel which contains the back and next buttons
            panelOne: '#panelOne', // these are the views extending Ext.Panel
            panelOneP: '#panelOneP',
            panelTwoP '#panelTwoP',
            panelThreeP: '#panelThreeP',
            panelFourP: '#panelFourP',
            panelFiveP: '#panelFiveP',
            panelSixPGraph: '#panelSixPGraph',
            panelOneC: '#panelOneC',
            panelTwoC: '#panelTwoC',
            panelThreeC: '#panelThreeC',
            panelFourC: '#panelFourC',
            panelFiveC: '#panelFiveC',
            panelSixCGraph: '#panelSixCGraph',
            piccs: '#piccs', // these two are images in the panelOne
            cVCs: '#CVCs'
        },

        control: {
            cVCs: {
                tap: 'cvcsClicked'
            },
            piccs: {
                tap: 'piccsClicked'
            },
            backButton: {
                tap: 'navigateBack'
            },
            nextButton: {
                tap: 'navigateNext'
            }
        }
    },

    navigateBack: function () {
        current = current - 1;
        this.addPanel(myPanel[current]);
    },

    navigateNext: function () {
        current = current + 1;
        this.addPanel(myPanel[current]);
    },

    addPanel: function (newPanel) {
        this.getPanelArea().removeAt(0);
    },

    var myNewPanel = Ext.create('Ext.Panel', {
        items: [{
            xtype: "" + newPanel + ""  // every view is given ID exactly as in the array
        }]
    });

    this.getPanelArea().add(myNewPanel);

    piccsClicked: function () {
        var current = this.getPiccs().getSrc();
        if (current == 'resources/images/checkBoxUnchecked.jpg') {
            this.getPiccs().setSrc('resources/images/checkBoxChecked.jpg');
        } else {
            this.getPiccs().setSrc('resources/images/checkBoxUnchecked.jpg');
        }
    },

    cvcsClicked: function () {
        var current = this.getCVCs().getSrc();
        if (current == 'resources/images/checkBoxUnchecked.jpg') {
            this.getCVCs().setSrc('resources/images/checkBoxChecked.jpg');
        } else {
            this.getCVCs().setSrc('resources/images/checkBoxUnchecked.jpg');
        }
    }
});