0

例如,我有 5 条记录。我应该要求用户确认下一步操作,

     var data = [];
     Ext.Msg.confirm('Confirm', String.format('Are you sure about {0} record?',
                    product['id']),
                    function (btn){
                        if(btn=='yes')  data.push(product['id']);

                    }
    });

 // here I want to get collected data
console.log(data); // gives [] - empty
4

1 回答 1

1

ExtJs 消息框是异步的,因此您添加产品的代码是正确的,但您要收集的部分是错误的。该部分在您确认之前执行。所以你应该添加一个函数来收集数据,并从消息框确认的回调方法中调用它:

var data = [];
function confirm(id){
     Ext.Msg.confirm('Confirm', String.format('Are you sure about {0} record?',
                    product['id']),
                    function (btn){
                        if(btn=='yes') {
                          data.push(product['id']);
                        }
                        if (id<4){ //or some terminal condition you have
                          confirm(newId) //show confirm for new id or next..
                        } else {
                          collectData(data);
                        }    
                    }
    );
}
function collectData (data){
 // here I want to get collected data
console.log(data); // gives [] - empty
}
于 2012-07-09T08:25:24.213 回答