我從GeoExt.data.FeatureStore/Ext.data.Store獲取使用PHP檢索的JSON填充的功能(地塊)的總數有問題。總數用作顯示錯誤消息(如果不返回任何功能)或包含搜索結果(地圖)的窗口的條件。我試圖使用getTotalCount,但無論檢索到的JSON是否包含特徵,都會返回0。 Ext JS版本3.4.1。代碼:Ext.data.Store getTotalCount總是返回0
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"
})
任何幫助將非常感激......
感謝您的回覆!是的,它返回的數字,所以我改變了===,沒有引號(是的,我的JavaScript「知識」是非常有限的...),但它仍然總是返回0 ... – mitahito