admin管理员组文章数量:1037775
I have a FilteringSelect in a form and I want to get it options in order to do an alphabetical insertion of a new option.
The FilteringSelect element is:
<select name="inv_ext" id="inv_ext" data-dojo-type="dijit.form.FilteringSelect">
<option class="opt_inv_ext" value="1">Aaaaa, Aaa</option>
<option class="opt_inv_ext" value="2">Ccccc, Ccc</option>
</select>
And the Javascript code to get and proccess each option is:
dojo.query(".opt_inv_ext").forEach(function(opt, i, nodelist){
...
}
The goal is to insert the following node:
<option class="opt_inv_ext" value="3">Bbbbb, Bbb</option>
between the two existing ones using the label as the parison value not the value attribute.
Any idea? Thanks in advance and sorry my english!
I have a FilteringSelect in a form and I want to get it options in order to do an alphabetical insertion of a new option.
The FilteringSelect element is:
<select name="inv_ext" id="inv_ext" data-dojo-type="dijit.form.FilteringSelect">
<option class="opt_inv_ext" value="1">Aaaaa, Aaa</option>
<option class="opt_inv_ext" value="2">Ccccc, Ccc</option>
</select>
And the Javascript code to get and proccess each option is:
dojo.query(".opt_inv_ext").forEach(function(opt, i, nodelist){
...
}
The goal is to insert the following node:
<option class="opt_inv_ext" value="3">Bbbbb, Bbb</option>
between the two existing ones using the label as the parison value not the value attribute.
Any idea? Thanks in advance and sorry my english!
Share Improve this question asked Dec 23, 2011 at 13:34 franipfpfranipfp 1601 silver badge9 bronze badges2 Answers
Reset to default 5It's easy to do if you use a store to back your list. I assume you use dojo 1.6>. Here is an example :
-In your HTML :
<input id="inv_ext">
-In javascript :
var store = new dojo.store.Memory({
data : [
{ type : 'options', value : 1, text : 'Aaaaa, Aaa' },
{ type : 'options', value : 2, text : 'Ccccc, Ccc' },
]
});
dojo.ready(function(){
var filteringSelect = new dijit.form.FilteringSelect({
id: "inv_ext",
name: "inv_ext",
store: store,
searchAttr : 'text',
query : {
type : 'options'
},
fetchProperties : {
sort : [ { attribute : "text" } ]
}
}, "inv_ext");
store.put({ type : 'options', value : 3, text : 'Bbbbb, Bbb' });
});
I resolved this problem as follows:
dijit.byId("select_id").store.root.add(dojo.create("option",{ value: "some", innerHTML: "label of option"}));
To remove the existing elements did just that:
var size = dijit.byId("select_id").store.root.removeChild.length;
for(var i=size; i>=0; i--){
dijit.byId("select_id").store.root.removeChild(dijit.byId("select_id").store.root.children[size-1]);
}
I have a FilteringSelect in a form and I want to get it options in order to do an alphabetical insertion of a new option.
The FilteringSelect element is:
<select name="inv_ext" id="inv_ext" data-dojo-type="dijit.form.FilteringSelect">
<option class="opt_inv_ext" value="1">Aaaaa, Aaa</option>
<option class="opt_inv_ext" value="2">Ccccc, Ccc</option>
</select>
And the Javascript code to get and proccess each option is:
dojo.query(".opt_inv_ext").forEach(function(opt, i, nodelist){
...
}
The goal is to insert the following node:
<option class="opt_inv_ext" value="3">Bbbbb, Bbb</option>
between the two existing ones using the label as the parison value not the value attribute.
Any idea? Thanks in advance and sorry my english!
I have a FilteringSelect in a form and I want to get it options in order to do an alphabetical insertion of a new option.
The FilteringSelect element is:
<select name="inv_ext" id="inv_ext" data-dojo-type="dijit.form.FilteringSelect">
<option class="opt_inv_ext" value="1">Aaaaa, Aaa</option>
<option class="opt_inv_ext" value="2">Ccccc, Ccc</option>
</select>
And the Javascript code to get and proccess each option is:
dojo.query(".opt_inv_ext").forEach(function(opt, i, nodelist){
...
}
The goal is to insert the following node:
<option class="opt_inv_ext" value="3">Bbbbb, Bbb</option>
between the two existing ones using the label as the parison value not the value attribute.
Any idea? Thanks in advance and sorry my english!
Share Improve this question asked Dec 23, 2011 at 13:34 franipfpfranipfp 1601 silver badge9 bronze badges2 Answers
Reset to default 5It's easy to do if you use a store to back your list. I assume you use dojo 1.6>. Here is an example :
-In your HTML :
<input id="inv_ext">
-In javascript :
var store = new dojo.store.Memory({
data : [
{ type : 'options', value : 1, text : 'Aaaaa, Aaa' },
{ type : 'options', value : 2, text : 'Ccccc, Ccc' },
]
});
dojo.ready(function(){
var filteringSelect = new dijit.form.FilteringSelect({
id: "inv_ext",
name: "inv_ext",
store: store,
searchAttr : 'text',
query : {
type : 'options'
},
fetchProperties : {
sort : [ { attribute : "text" } ]
}
}, "inv_ext");
store.put({ type : 'options', value : 3, text : 'Bbbbb, Bbb' });
});
I resolved this problem as follows:
dijit.byId("select_id").store.root.add(dojo.create("option",{ value: "some", innerHTML: "label of option"}));
To remove the existing elements did just that:
var size = dijit.byId("select_id").store.root.removeChild.length;
for(var i=size; i>=0; i--){
dijit.byId("select_id").store.root.removeChild(dijit.byId("select_id").store.root.children[size-1]);
}
本文标签: javascriptHow to get FilteringSelect options and add a new one with dojoStack Overflow
版权声明:本文标题:javascript - How to get FilteringSelect options and add a new one with dojo - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745620441a2159539.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论