最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Select and remove items from dojo.form.Multiselect - Stack Overflow

programmeradmin0浏览0评论

I have two sets of dojo.form.Multiselect boxes on a Wizard Dialog. They have the ability to transfer items between them like this example: Testing Multiselect from Widget. I also have a checkbox on the form and when a user clicks on it, I need to:

  1. Select all items in the first Multiselect box
  2. Move them to the right side select box via addSelected()
  3. Clear the first list of all items

The invsertSelection option doesn't work because if any items are selected at the time the checkbox is clicked, only the unselected items are selected and moved. I don't see a way in the API to do this nor a reliable method in the codesphere. Any suggestions?

I have two sets of dojo.form.Multiselect boxes on a Wizard Dialog. They have the ability to transfer items between them like this example: Testing Multiselect from Widget. I also have a checkbox on the form and when a user clicks on it, I need to:

  1. Select all items in the first Multiselect box
  2. Move them to the right side select box via addSelected()
  3. Clear the first list of all items

The invsertSelection option doesn't work because if any items are selected at the time the checkbox is clicked, only the unselected items are selected and moved. I don't see a way in the API to do this nor a reliable method in the codesphere. Any suggestions?

Share Improve this question asked Jun 8, 2012 at 14:48 JFOXJFOX 2451 gold badge6 silver badges15 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Figured out a solution from looking at Dojo Docs and other code:

var selectItem1 = dijit.byId('firstSelectBox');

// Deselect all and invert to Select all
selectItem1.set("value",[]);
selectItem1.invertSelection();

//Move items to right box
var selectItem2 = dijit.byId('secondSelectBox');
selectItem2.addSelected(selectItem1);

Basically the addSelected does a dom query on the select to see which options are marked as selected :

query("option",this.containerNode).filter(function(n){
return n.selected; // Boolean
});

so you could basically select everything by doing :

query("option", myMultiSelect.containerNode).forEach(function(n){
    n.selected = true; // Boolean
});

then use addSelected... somethign like that should do the trick.

发布评论

评论列表(0)

  1. 暂无评论