动态向面板添加标签不会刷新面板

时间:2015-04-17 08:22:05

标签: javascript extjs extjs4 sencha-touch extjs4.1

我有循环:

for (var key in myMap) {
                          if (myMap.hasOwnProperty(key)) {
                              propertiesPanel.add(new Ext.form.Label({
                                  text: key+':'+myMap[key]
                              }));
                              propertiesPanel.doLayout();

                          }
                        }

但是如果我在hashmap myMap中有500个键,它会将所有标签添加到面板,最后刷新过程发生。但我想逐渐看到添加过程。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

尝试递归函数

而不是循环
addFields(500); //Adding 500 fields
fieldsAdded = 0
addFields = function(fieldCount) {
    propertiesPanel.add(new Ext.form.Label({
        text: 'Some text'
    }));
    propertiesPanel.doLayout();
    fieldsAdded++;
    if (fieldsAdded < fieldCount) {
        Ext.Function.defer(function() {
            addFields(fieldCount)
        }, 100, this);
    }
}