将项目添加到 Dojo Select dijit 的顶部,但不能 select 第二个项目
Adding an item to the top of a Dojo Select dijit, but can't select the second item
我有两个基于同一个数据存储的 Select dijit。第一个 dijit 是必需的响应,第二个 dijit 是可选的响应。对于第二个 dijit,我想将附加项 "None" 添加到列表的顶部。但是,当我这样做时,我不能 select 列表中的第二个项目。在这个JSBin中,如果你在第二个dijit中select"General lakebed mapping",返回的值就是添加的item"None".
require(["dijit/form/Select",
"dojo/data/ObjectStore",
"dojo/store/Memory",
"dojo/domReady!"
], function (Select, ObjectStore, Memory) {
var data = [
{ id: 0, label: 'General lakebed mapping' },
{ id: 1, label: 'Bathymetry/Digital Elevation Model' },
{ id: 2, label: 'Ferrous object detections/magnetic anomalies' },
{ id: 3, label: 'Ground-truth data' },
{ id: 4, label: 'Lakebed color' },
{ id: 5, label: 'Lakebed surface type, hardness/smoothness/slope' },
{ id: 6, label: 'Sub-bottom geology' }
];
var store = new Memory({
data: data
});
var os = new ObjectStore({ objectStore: store });
var s = new Select({
store: os,
sortByLabel: false
}, "target");
s.startup();
data.unshift({ id: -1, label: 'None' })
store.setData(data);
var s1 = new Select({
store: os,
sortByLabel: false
}, "target1");
s1.startup();
s1.on("change", function () {
console.log("my value: ", this.get("value"))
});
})
不要将值 0
用作 ID。它在 JavaScript 中是一个错误的值,我怀疑 Select dijit 源在某处将它视为错误并失败了。只需使用另一个值代替它。
我有两个基于同一个数据存储的 Select dijit。第一个 dijit 是必需的响应,第二个 dijit 是可选的响应。对于第二个 dijit,我想将附加项 "None" 添加到列表的顶部。但是,当我这样做时,我不能 select 列表中的第二个项目。在这个JSBin中,如果你在第二个dijit中select"General lakebed mapping",返回的值就是添加的item"None".
require(["dijit/form/Select",
"dojo/data/ObjectStore",
"dojo/store/Memory",
"dojo/domReady!"
], function (Select, ObjectStore, Memory) {
var data = [
{ id: 0, label: 'General lakebed mapping' },
{ id: 1, label: 'Bathymetry/Digital Elevation Model' },
{ id: 2, label: 'Ferrous object detections/magnetic anomalies' },
{ id: 3, label: 'Ground-truth data' },
{ id: 4, label: 'Lakebed color' },
{ id: 5, label: 'Lakebed surface type, hardness/smoothness/slope' },
{ id: 6, label: 'Sub-bottom geology' }
];
var store = new Memory({
data: data
});
var os = new ObjectStore({ objectStore: store });
var s = new Select({
store: os,
sortByLabel: false
}, "target");
s.startup();
data.unshift({ id: -1, label: 'None' })
store.setData(data);
var s1 = new Select({
store: os,
sortByLabel: false
}, "target1");
s1.startup();
s1.on("change", function () {
console.log("my value: ", this.get("value"))
});
})
不要将值 0
用作 ID。它在 JavaScript 中是一个错误的值,我怀疑 Select dijit 源在某处将它视为错误并失败了。只需使用另一个值代替它。