我正在使用 arcgis Javascript Api 3.7(其中包括 dojo 1.9.1),并且我一直在开发一个自定义模板化 dijit,它有两个 filterSelect 控件,第一个被正确填充,我有第二个被填充时用户从第一个项目中选择一个项目,在该特定时刻设置其数据存储。第二个filteringSelect每次都会正确填充,但是onchange事件会发生一些事情,因为函数处理程序永远不会被触发,我需要对第二个FilterinSelect的onchange事件做一些其他的工作。
似乎有些东西被第二个过滤选择弄乱了(用处理程序上下文猜测一些东西),但我还想不通。
我的两个过滤控件模板声明(我的 dijit html 模板的一部分:
<tr>
<td>
Capa:
</td>
<td>
<input data-dojo-type="dijit.form.ComboBox" name="layerDijit" id="layerDijit"
data-dojo-props="autoComplete:true, required:true, searchAttr:'name', style:'width:100%;'"
data-dojo-attach-point="layerDijit" data-dojo-attach-event="change:_handleLayerSelected"/>
</td>
</tr>
<tr>
<td>
Campo:
</td>
<td>
<input data-dojo-type="dijit.form.FilteringSelect" name="fieldDijit" id="fieldDijit"
data-dojo-props="autoComplete:true, required:true, searchAttr:'name', style:'width:100%;'"
data-dojo-attach-point="fieldDijit" data-dojo-attach-event="change:_handleFieldSelected"/>
</td>
</tr>
Dijit JS 脚本:
填充第一个过滤选择的代码
postCreate: function() {
this.inherited(arguments);
....
this.rootMapLayer = this.map.getLayer("ELAPAS");
if (this.rootMapLayer.loaded){
this.listLayers(this.rootMapLayer);
}
else{
this.rootMapLayer.on("load", lang.hitch(this, this.listLayers));
}
//enlace de eventos (tested this, and it doesn't work for the second filtering select either)
//this.fieldDijit.on('change', lang.hitch(this, this._handleFieldSelected));
//this.layerDijit.on('change', lang.hitch(this, this._handleLayerSelected));
},
listLayers: function() {
var layerInfos = [];
layerInfos = array.filter(this.rootMapLayer.layerInfos,function(info,index){
return info.subLayerIds === null;
});
if(layerInfos.length === 0) {
console.error("No se encontro ninguna capa para el servicio de mapa seleccionado");
return;
}
var layersStore = new Memory({
data: layerInfos
});
this.layerDijit.set('store', layersStore);
},
处理第一个过滤选择中的选择更改的代码称为 layerDijit 并为第二个过滤选择(FieldDijit)加载数据:
_handleLayerSelected: function () {
var selectedLayer = this.layerDijit.item;
if(this.getSelectedLayerUrl() === null) {
return;
}
//Se limpia el campo actual
this.fieldDijit.set("value", "");
//Se arma la url del layer específico para traer la información de la capa (sus campos)
var layerUrl = this.rootMapLayer.url + "/" + selectedLayer.id;
esri.request({
url: layerUrl,
content: {
f: "json"
},
handleAs: "json",
callbackParamName: 'callback',
load: lang.hitch(this, '_handleLayerInfo'),
error: lang.hitch(this, '_handleLayerInfoError')
});
},
_handleLayerInfo: function(data) {
var layerInfo = data;
if (!layerInfo.fields) {
console.error("No se pudo obtener la información de los campos de la capa");
return;
}
var fieldsStore = new Memory({
data: layerInfo.fields
});
this.fieldDijit.set('store', fieldsStore);
},
getSelectedLayerUrl: function(){
var selectedLayer = this.layerDijit.item;
if(!selectedLayer) {
return null;
}
//Se arma la url del layer específico para traer la información de la capa (sus campos)
return this.rootMapLayer.url + "/" + selectedLayer.id;
},
_handleLayerInfoError: function(err){
console.error(err);
},
没有被触发的函数,应该处理第二个过滤选择的 se change 事件的函数:
_handleFieldSelected: function () {
alert("doesn't get fired");
/*var selectedField = this.fieldDijit.item;
if(!selectedField) {
return;
} */
},
你能给我一些关于这个问题的建议吗?,我做错了什么?
提前致谢