Esri Query,JQuery Ajax:不喜欢Ajax返回



我有一个JQuery Ajax调用,如下代码所示:

 $.ajax({
        type: "POST",
        url: "spaceplanning_database.asmx/GetRoomDataAttributes",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            restricted_attributes_global = msg.d;
            console.log(msg.d);// "OBJECTID", "Room", "Floor", "OBJECTID_BLDG", "Room_GUID", "PKey", "SHAPE"
            var featureLayer = new FeatureLayer("http://gisserver/xxx", {
                mode: FeatureLayer.MODE_SNAPSHOT,
            //outFields: [restricted_attributes_global], //doesn't work
            outFields: ["OBJECTID", "Room", "Floor", "OBJECTID_BLDG", "Room_GUID", "PKey", "SHAPE"],
            });
            map.addLayer(featureLayer);
        }
    });

基本上,这会调用C#Web服务并获取一些数据库列名(如OBJECTID、Room)。根据,列名在Web服务中用双引号填充

string allowed_loc = """ + reader["COLUMN_NAME"] + """;

在一个循环中。

上面代码中的console.log显示了msg.d的输出;但当它被分配给restricted_attributes_global变量并在Esri查询中使用时,我会看到一个错误:

esri.layers.FeatureLayer: unable to find '"OBJECTID","Room","Floor","OBJECTID_BLDG","Room_GUID","PKey","SHAPE"' field in the layer 'fields'

但是,与上面的代码一样,我将console.log值复制/粘贴为硬编码,然后Esri查询就可以工作了。也许我需要用不同的方式在C#中放置双引号,或者在Ajax调用中键入其他字符集?可能会发生什么?

我认为这个问题介于JQuery、C#和Esri查询之间。

正如我在上面的Comment中所指出的,我必须创建一个数组对象来传递给outFields变量,但我无法使其在FeatureLayer模式下工作。所以我最终使用了QueryTask。以下是相关代码:

...//code as above this line
restricted_attributes_global = msg.d;
var array = restricted_attributes_global.split(',');//converting to array
var query = new esri.tasks.Query();
var queryTask = new esri.tasks.QueryTask("http://gisserver/xx");
query.where = "OBJECTID_BLDG=12";
query.outSpatialReference = { wkid: 102100 };
query.returnGeometry = true;
query.outFields = [array];// passing the array

无论如何,QueryTask是我的应用程序的更好途径。C#代码现在被更改为删除双引号:

allowed_attributes.Add(reader["COLUMN_NAME"].ToString());

现在一切都很有魅力。

HTH。

最新更新