开发者

dynamically add new item in combo box without using data store

I have multiple combo boxes on my page and each one of them are holding different values so i don't want to create a separate data store for each of them , rather i want a way to dynamically add new values to those combo boxes without using data store.

 var comboOne = new Ext.form.ComboBox({
            value: val,
            name:'L_PHONE',
                store: [val],
                displayField:'value',
                typeAhead: true,
                mode: 'local',开发者_开发知识库
                forceSelection: true,
                triggerAction: 'all',
                width:100,

                selectOnFocus:true,
                applyTo: id
            });

so i just need a way to add new values dynamically like comboOne.setValue('NEW') but this function only add value at the top and overrides the newly added value


In the context of your question, there are two things associated with ExtJS combobox.
1. The options that you see in the dropdown when you click on the trigger
2. The value that the combo is holding at any given point of time. If you submit the form, this is the value that is going to be submitted. You can modify the value by selecting an option in #1 (by this, I don't mean that selecting is not the only way to set the value)

Your question is related to #1 above but what you are trying to do is modifying the value in #2

Now that it is clear why what you are doing is not working the way you expect it to, here is the answer to your question -

The option list in Combobox in ExtJS is always backed by a store. To be able to add an option in the options list that appears as a dropdown, you will have to add the option (record) to the store backing the particular combobox.

This is as simple as -

comboOne.getStore().add(comboOne.getStore().recordType({value:'NEWVAL'});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜