简体   繁体   English

如何一次显示所有回调结果(格式化)

[英]How to display all callback results (formatted) at once

I have a callback that sends data once they are ready (eg, an array of 5 names after I do a left-click). 我有一个回调,一旦数据准备好就发送数据(例如,在我单击鼠标左键后,由5个名称组成的数组)。 I want to display all the sent data to an Ext.Panel, but it gets only displayed in the Ext.Panel the last object of the array (eg, array goes from 1 to 5, and 1 to 4 appears really quick and in the end only 5 remains). 我想将所有发送的数据显示到Ext.Panel中,但是它仅显示在Ext.Panel中数组的最后一个对象中(例如,数组从1到5,而1到4则显示得很快,并且在最后只剩下5个)。 Besides, I want to display these data by rows, and not like an array. 此外,我想按行而不是像数组那样显示这些数据。 How can I achieve that? 我该如何实现?

Code: 码:

  trigger: function(e) {
    /* define some here */
    /*...*/
    $.ajax({
      /*...*/
      success: function(result){
        /*...*/
        var temp1 = 'name1';
        callback(temp1);
      }
    });
    $.ajax({
      /*...*/
      success: function(result){
        /*...*/
        var temp2 = 'name2';
        callback(temp2);
      }
    });
function callback(result){
    console.log('all results but they appear one by one here like: ' + result);

        var store = new Ext.Panel({
            html: result,
            border: false,
            bodyStyle: {
                'padding': '6px'
            },
            autoHeight: true
        });
};

Since you know hom many ajax requests you do (5), I suggest you to create a global variable wich will memorize the result of all your callback and insert into your panel once they are all loaded : 既然您知道要执行许多ajax请求(5),建议您创建一个全局变量,该操作将记住所有回调的结果,并在它们全部加载后插入面板中:

var myData = [];    

function callback(result){
    myData.push(result);
    if (myData.length == 5) {
          var store = new Ext.Panel({
              html: myDataFormated , // Here add some style by transforming myData array
              border: false,
              bodyStyle: {
                 'padding': '6px'
              },
              autoHeight: true
          });   
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM