0

我有一个关于将字符串从 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&parameters=" + "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]

这些是我已经测试过的案例:

  1. url: http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom: 这会将整个表“boreholes_point_wgs84”生成为 GeoJSON。
  2. url: http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom&parameters=station ilike '%llena%': 这只会生成一个特征,即“站”列中具有“llena”的特征。因此,通过这种方式我可以通过搜索表单找到该功能。

我在想的是,如果我可以传递我在“textfield”中输入的这两个字符串,并以它可以捕获这两个单词和形式的方式修改“url”,例如,我放在上面的第二种情况。我在玩这个:

url: http://localhost/postgis_geojson.php?geotable=boreholes_point_wgs84&geomfield=geom&parameters=" + "column" + ilike '%"string"%',因此使用我在每个 xtype 下方指定的“id”,但它不起作用。

感谢您对此的任何支持,在此先感谢,

此致,

格里

4

2 回答 2

0

正确的方法是简单的表单提交。文本输入值将在表单发布中发送到服务器。服务器端应该解析提交的值并做必要的事情。这与使用纯 HTML 和任何服务器端框架没有什么不同。

或者,您可以强制您的表单使用 HTTP GET 方法而不是 POST 提交,然后您的输入值将成为您的 URL 的一部分。在 ExtJS 中,您使用“方法”配置。请参阅 API 文档:http ://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.Basic-cfg-method

编辑:如果您对实际“提交”表单根本不感兴趣,您可以像这样获取字段值:form.findField('myField').value

于 2012-10-01T18:03:39.600 回答
0

我很确定这个解决方案将有助于理解如何解决这个问题,我自己解决了。

于 2013-02-14T16:37:47.263 回答