How to dynamically add list items in extjs list box (multiselect)

Source: Internet
Author: User

Because it is the ArrayStore automatically loaded during creation (Keyword: data: ds), there is no dynamic addition example, but our project needs to have three list boxes, the content of the last two items must be dynamically loaded according to the content of the first list box. Therefore, when selecting the content of the first list box, the content of the last two items must be dynamically filled. I admire the example writers of exjts. They did not write the functions that should be embodied in the examples, including the examples of previous versions 2.2, which were not found on the Internet, I found how to dynamically control the list data in a day. first of all, my method is not an official method, but I just think about it. Below is a method to dynamically add list items.
Prior to the method, my store on the multiselect object was defined as follows:
Copy codeThe Code is as follows:
FlowDs = new Ext. data. ArrayStore ({
Data: [[1, 123,123],
Fields: ['value', 'text']
});

(1) var toflowStore = msForm. getForm (). findField ('toflow'). store; // obtain the store object of the multiselect object based on the name;
(2) create an Ext. data. Record object. I have been thinking about how to add it for a long time. I also blame myself for being too stupid:
Copy codeThe Code is as follows:
Var record = new Object ();
Record. value = "2 ";
Record. text = "3 ";
Var records = new Ext. data. Record (record );

(3) Add the created Ext. data. Record object to the store object of multiselect:
ToflowStore. add (record1 );
In the preceding three steps, you can dynamically add list items to the list by using multisleect. You can use the remove ()/removeAll () method to delete an item, you can use the ItemSelector of the sample code. js.
After the above analysis, we can roughly estimate the creation rules of multiselect. In the store, there is an attribute fields: ['value', 'text'], then at the time of creation, the system will create the content in the attribute data: [[123,123] as an object in a loop, and then write it to its store object, similar to the following code:
Copy codeThe Code is as follows:
Var item = [], itemObj, record;
For (var I = 0; I <this. data. length; I ++ ){
Item = this. data [I];
ItemObj = new Object ();
ItemObj. value = item [0];
ItemObj. text = item [1];
Record = new Ext. data. Record (itemObj );
This. store. add (record );
}

The above is just my guess. The extjs engineers have not carefully studied whether to design their programs in this way.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.