简体   繁体   English

从 Sencha Touch 中的 javascript 数组动态添加项目

[英]Adding items dynamically from javascript array in Sencha Touch

I have this code我有这个代码

    var filter = {
        items: [{
            xtype: 'fieldset',
            title: 'Choose',
            items: [
               // I need to put checkboxes here
            ]
        }]
    };

I need to dynamically add checkbox items:我需要动态添加复选框项目:

{
   xtype: 'checkboxfield',
   name: 'city[]',
   label: 'City name',
   checked: false,
}

The data that I need to add is stored in JS array, and checkbox can be checked or unchecked我需要添加的数据存储在JS数组中,复选框可以选中或不选中

Please help, Thank you in advance请帮忙,提前谢谢

What is your issue?你的问题是什么? When do you add?你什么时候加? What is the event?什么是事件?

filter.items[0].items[filter.items[0].items.length] = {
   xtype: 'checkboxfield',
   name: 'city[]',
   label: 'City name',
   checked: false,
}

or或者

var checkbox = {
       xtype: 'checkboxfield',
       name: 'city[]',
       label: 'City name',
       checked: false,
    }
var itemArr = filter.items[0].items;
itemArr[itemArr.length]=checkbox;

What is filter , is it a Container or does it extend from it (Panel, FormPanel, etc.)?什么是filter ,它是一个Container还是从它扩展而来(Panel、FormPanel 等)?

If so, you can use theadd() method to dynamically add to it.如果是这样,您可以使用add()方法对其进行动态添加。

It's also good to note, that posting in the Sencha Forums will get your a much faster response.还需要注意的是,在Sencha 论坛上发帖将使您得到更快的响应。

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

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