我有一个以编程方式创建的dojo.form.FilteringSelect
小部件。dojo.Dialog
我第onChange
一次FilteringSelect
选择并进入FilteringSelect
. 以后每次我选择新的东西时,该onChange
事件都不会触发。
onChange
在为我的语句提供参数时,我尝试过声明该属性new FilteringSelect
。我试过使用dojo.connect
. 我试过了mySelectDijit.on
。都有相同的效果。
var select = new dijit.form.FilteringSelect({
id : "fields-select-" + expNum,
store : store,
required : false,
intermediateChanges : true
}, fieldinput);
dojo.connect(select, 'onChange', LoadOperatorValue);
onChange
每次更改时如何触发事件FilteringSelect
?
更新:
我已经添加了相关代码。此代码基于 ArcGIS Javascript API v3.3,其中包括 Dojo。
dojo.require("dijit.Dialog");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.store.Memory");
dojo.require("dijit.form.MultiSelect");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.Textarea");
dojo.require("dijit.form.NumberSpinner");
dojo.require("dijit.form.DateTextBox");
var expNum = 1;
var queryDiv;
var layer;
var dialog;
function CreateDialog(lyr) {
layer = lyr;
queryDiv = dojo.create("div", {
id : "queryDiv"
});
var buttonInput = dojo.create("button", {
id : "button"
}, queryDiv);
var button = new dijit.form.Button({
id : "addExpression",
label : "Add Expression",
onClick : function() {
BuildExpression(layer);
}
}, buttonInput);
BuildExpression(layer)
dialog = new dijit.Dialog({
title : "Query: " + layer.layerObject.name,
content : queryDiv,
style : "width: 600px"
});
dialog.show();
}
function BuildExpression(layer) {
var expDiv = dojo.create("div", {
class : "expression",
id : "expression-" + expNum
}, queryDiv);
var filterDiv = dojo.create("div", {
class : "filter",
id : "filter-" + expNum
}, expDiv);
var fieldSpan = dojo.create("span", {
id : "field-" + expNum,
class : "field"
}, filterDiv);
var operatorSpan = dojo.create("span", {
id : "operator-" + expNum,
class : "operator"
}, filterDiv);
var valueSpan = dojo.create("span", {
id : "value-" + expNum,
class : "value"
}, filterDiv);
var removeSpan = dojo.create("span", {
id : "remove-" + expNum,
class : "remove"
}, filterDiv);
var removeInput = dojo.create("button", {
id : "button"
}, removeSpan);
var removeButton = new dijit.form.Button({
id : "removeExpression" + expNum,
label : "Remove",
onClick : function() {
dojo.destroy(expDiv);
}
}, removeInput);
var fieldinput = dojo.create("input", {
id : "field-input-" + expNum
}, fieldSpan);
var fields = [];
dojo.forEach(layer.layerObject.fields, function(field, index) {
if (index < layer.layerObject.infoTemplate.info.fieldInfos.length && layer.layerObject.infoTemplate.info.fieldInfos[index].visible == true) {
field.operatorSpan = operatorSpan;
field.valueSpan = valueSpan;
fields.push({
name : field.alias,
id : field
});
}
});
var store = new dojo.store.Memory({
data : fields
});
var select = new dijit.form.FilteringSelect({
id : "fields-select-" + expNum,
store : store,
required : false,
intermediateChanges : true
}, fieldinput);
dojo.connect(select, 'onChange', LoadOperatorValue);
expNum++
}
function LoadOperatorValue(field) { debugger;
dojo.empty(field.operatorSpan);
dojo.empty(field.valueSpan);
if ("domain" in field && "codedValues" in field.domain) {
field.operatorSpan.innerHTML = "IS";
var sel = dojo.create("select", {
id : "multiselect-" + expNum
}, field.valueSpan);
dojo.forEach(field.domain.codedValues, function(cv, index) {
dojo.create("option", {
innerHTML : cv.name,
value : cv.code
}, sel);
});
var multiselect = new dijit.form.MultiSelect({}, sel);
} else if (field.type == "esriFieldTypeString") {
var operatorInput = dojo.create("input", {
id : "operator-input"
}, field.operatorSpan);
var operators = [{
name : "IS",
id : " = "
}, {
name : "IS NOT",
id : " <> "
}, {
name : "LIKE",
id : " LIKE "
}, {
name : "NOT LIKE",
id : " NOT LIKE "
}];
var opStore = new dojo.store.Memory({
data : operators
});
var select = new dijit.form.FilteringSelect({
id : "operator-select-" + expNum,
store : opStore,
required : false
}, operatorInput);
var valueInput = dojo.create("input", {
id : "value-input"
}, field.valueSpan);
if (field.length < 50) {
var textBox = new dijit.form.TextBox({
id : "value-input-" + expNum
}, valueInput);
} else {
var textBox = new dijit.form.Textarea({
id : "value-input-" + expNum
}, valueInput);
}
} else if (field.type == "esriFieldTypeDouble" || field.type == "esriFieldTypeSingle" || field.type == "esriFieldTypeInteger" || field.type == "esriFieldTypeSmallInteger") {
var operatorInput = dojo.create("input", {
id : "operator-input"
}, field.operatorSpan);
var operators = [{
name : "=",
id : " = "
}, {
name : "!=",
id : " <> "
}, {
name : "<",
id : " < "
}, {
name : "<=",
id : " <= "
}, {
name : ">",
id : " > "
}, {
name : ">=",
id : " >= "
}];
var opStore = new dojo.store.Memory({
data : operators
});
var select = new dijit.form.FilteringSelect({
id : "operator-select-" + expNum,
store : opStore,
required : false
}, operatorInput);
var valueInput = dojo.create("input", {
id : "value-input"
}, field.valueSpan);
var constraints = {};
if ("domain" in field && "range" in field.domain) {
constraints.min = field.domain.range.min;
constraints.max = field.domain.range.max;
}
if (field.type == "esriFieldTypeDouble" || field.type == "esriFieldTypeSingle") {
constraints.places = 2;
}
var numberSpinner = new dijit.form.NumberSpinner({
id : "value-input-" + expNum
}, valueInput);
} else if (field.type == "esriFieldTypeDate") {
var operatorInput = dojo.create("input", {
id : "operator-input"
}, field.operatorSpan);
var operators = [{
name : "IS",
id : " = "
}, {
name : "IS NOT",
id : " <> "
}, {
name : "Before",
id : " < "
}, {
name : "Before or IS",
id : " <= "
}, {
name : "After",
id : " > "
}, {
name : "After or IS",
id : " >= "
}];
var opStore = new dojo.store.Memory({
data : operators
});
var select = new dijit.form.FilteringSelect({
id : "operator-select-" + expNum,
store : opStore,
required : false
}, operatorInput);
var valueInput = dojo.create("input", {
id : "value-input"
}, field.valueSpan);
var dateTextBox = new dijit.form.DateTextBox({
id : "value-input-" + expNum
}, valueInput);
} else {
}
}