Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button 只需在每次单击按钮时计数-Ext JS_Button_Extjs_If Statement_Count - Fatal编程技术网

Button 只需在每次单击按钮时计数-Ext JS

Button 只需在每次单击按钮时计数-Ext JS,button,extjs,if-statement,count,Button,Extjs,If Statement,Count,因此,我在主app.js中有#add_按钮: { xtype: 'button', text: 'Add', itemId: 'add_criteria' } 我这里有一个控制器,它会监听每次单击,并在每次单击“添加”按钮时尝试添加1: Ext.define('AM.controller.Add', { extend: 'Ext.app.Controller', init: function() { this.control({ '#ad

因此,我在主app.js中有#add_按钮:

{ xtype: 'button', text: 'Add', itemId: 'add_criteria' }
我这里有一个控制器,它会监听每次单击,并在每次单击“添加”按钮时尝试添加1:

Ext.define('AM.controller.Add', {
    extend: 'Ext.app.Controller',
    init: function() {
        this.control({
            '#add_button': {
                click: this.add
            }
        });
    },

    add: function(btn) {
        var count = 0;
        if (count <= 3)
        {
            count++;
            console.log('Count is now ' + count;

        }
        else {
            console.log('wut');
        }

    }
});
Ext.define('AM.controller.Add'{
扩展:“Ext.app.Controller”,
init:function(){
这是我的控制({
“#添加按钮”:{
单击:this.add
}
});
},
添加:功能(btn){
var计数=0;

如果(count您正在使用
count
作为局部变量,并在每次单击按钮时将其初始化为0。您需要将
count
作为控制器的成员变量

Ext.define('AM.controller.Add', {
    extend: 'Ext.app.Controller',
    init: function() {
        this.count = 0;
        this.control({
            '#add_button': {
                click: this.add
            }
        });
    },

    add: function(btn) {
        if (this.count <= 3)
        {
            this.count++;
            console.log('Count is now ' + this.count);

        }
        else {
            console.log('wut');
        }

    }
});
Ext.define('AM.controller.Add'{
扩展:“Ext.app.Controller”,
init:function(){
此值为0.count;
这是我的控制({
“#添加按钮”:{
单击:this.add
}
});
},
添加:功能(btn){

if(this.count)您在哪里得到未定义?console.log调用?您的
count
逻辑没有意义。每次单击时它都会重置为零。这很好,但似乎不符合布局(hbox)我的面板。我怎么能让它这样做?我不知道你在问什么…控制器与你的hbox布局有什么关系?处理程序在我的面板中添加了一个组合框,这很好。但是它没有与面板中已经呈现的组合框对齐。听起来像是一个不同的和不相关的问题,你可能需要调试一段时间如果你想不出来,就写一篇新文章(带代码)。