3

我在向导对话框上有两组 dojo.form.Multiselect 框。他们有能力在他们之间传输项目,比如这个例子:Testing Multiselect from Widget。我在表单上还有一个复选框,当用户点击它时,我需要:

  1. 选择第一个多选框中的所有项目
  2. 通过 addSelected() 将它们移动到右侧选择框
  3. 清除所有项目的第一个列表

inversertSelection 选项不起作用,因为如果在单击复选框时选择了任何项目,则只会选择和移动未选择的项目。我在 API 中看不到执行此操作的方法,也没有在代码圈中看到可靠的方法。有什么建议么?

4

2 回答 2

4

通过查看 Dojo Docs 和其他代码找到了解决方案:

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);
于 2012-06-08T20:25:02.430 回答
0

基本上 addSelected 对 select 进行 dom 查询,以查看哪些选项被标记为 selected :

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

因此您基本上可以通过以下方式选择所有内容:

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

然后使用 addSelected... 这样的东西应该可以解决问题。

于 2012-06-11T07:39:28.657 回答