我有一个关于将字符串从 Ext.formPanel 文本字段传递到代码的另一部分的问题。问题是我在 formPanel 中有两个“文本字段”,我希望在其中输入的单词作为代码中“url”的一部分。可能你会问,这家伙为什么要那个?这是因为我使用的“url”有一个 PHP 脚本,它生成存储在 postgis db 表中的特性作为 GeoJSON。
这是代码:
[CODE]
// define the data source
var protocol = new OpenLayers.Protocol.HTTP({
url: "http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom¶meters=" + "column" + ilike '%"string"%',
format: new OpenLayers.Format.GeoJSON({
ignoreExtraDims: true,
'internalProjection': new OpenLayers.Projection("EPSG:900913"),
'externalProjection': new OpenLayers.Projection("EPSG:4326")
})
});
formPanel = new GeoExt.form.FormPanel({
title: "Place Name Search",
height: 150,
region: "north",
protocol: protocol,
items: [{
xtype: "textfield",
id: "column",
emptyText: "Choose table column",
fieldLabel: "Choose table column",
width: 200,
allowBlank: false
}, {
xtype: "textfield",
id: "string",
emptyText: "Search inside table",
fieldLabel: "Enter a word to search",
width: 200,
allowBlank: false
}],
listeners: {
actioncomplete: function(form, action) {
features = action.response.features;
store.loadData(features);
vm=map.getLayersByName("Results");
if(vm.length===0){
vecLayer = new OpenLayers.Layer.Vector("Results");
map.addLayer(vecLayer);
store.bind(vecLayer);
select.bind(vecLayer);
}
}
},
buttons: [{text: 'search',
handler: function(){
formPanel.search();
}
}],
keys: [{ key: [Ext.EventObject.ENTER],
handler: function() {
formPanel.search();
}
}]
});
[/CODE]
这些是我已经测试过的案例:
- url:
http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom
: 这会将整个表“boreholes_point_wgs84”生成为 GeoJSON。 - url:
http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom¶meters=station ilike '%llena%'
: 这只会生成一个特征,即“站”列中具有“llena”的特征。因此,通过这种方式我可以通过搜索表单找到该功能。
我在想的是,如果我可以传递我在“textfield”中输入的这两个字符串,并以它可以捕获这两个单词和形式的方式修改“url”,例如,我放在上面的第二种情况。我在玩这个:
url: http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom¶meters=" + "column" + ilike '%"string"%'
,因此使用我在每个 xtype 下方指定的“id”,但它不起作用。
感谢您对此的任何支持,在此先感谢,
此致,
格里