我从使用 PHP 检索的 JSON 填充的 GeoExt.data.FeatureStore/Ext.data.Store 获取要素(地块)总数时遇到问题。总数用作显示错误消息(如果未返回任何特征)或包含搜索结果(地图)的窗口的条件。我尝试使用 getTotalCount 但无论检索到的 JSON 是否包含功能,它都会返回 0。分机 JS 版本 3.4.1。代码:
var store = new GeoExt.data.FeatureStore({
layer: parcels,
fields: [{
name: "name"
}
],
proxy: new GeoExt.data.ProtocolProxy({
protocol: new OpenLayers.Protocol.HTTP({
url: "php/DB2GeoJSON.php",
format: new OpenLayers.Format.GeoJSON()
})
})
});
var formPanel = new GeoExt.form.FormPanel({
frame: true,
title: "Search for parcels",
protocol: new OpenLayers.Protocol.HTTP({
url: "php/DB2GeoJSON.php",
format: new OpenLayers.Format.GeoJSON()
}),
items: [{
xtype: "textfield",
name: "name",
fieldLabel: "Parcel ID",
value: ""
}
],
renderTo: "parcel_search",
listeners: {
actioncomplete: function (form, action) {
json = Ext.util.JSON.decode(action.response.priv._object.responseText);
features = action.response.features;
store.loadData(features);
}
}
});
formPanel.addButton({
text: "Search",
handler: function () {
this.search();
var totalCount = store.getTotalCount();
if (totalCount = "0") {
Ext.Msg.alert("Alert", "No such parcel ID!");
} else {
new Ext.Window({
title: "Search result"
height: 400,
width: 600,
modal: true,
layout: "border",
draggable: false,
resizable: false,
closeAction: "hide",
items: [{
region: "center",
id: "mappanel",
xtype: "gx_mappanel",
map: map,
split: true
}
]
}).show();
}
},
scope: formPanel,
renderTo: "parcel_search"
})
任何帮助都感激不尽...