我在javascript中执行了一个查询任务,查询单个服务中的2个层。它返回一些值,包括一个本地权限。我已经创建了一个具有该本地权限名称的JSON文件,我想要做的是创建一个下拉列表,显示JSON字符串中包含的本地权限URL值(由queryTask生成)。这是queryTask代码:
var queryTask = new QueryTask("http://rest/services/live/SEARCH/MapServer/2");
var query = new Query();
query.returnGeometry = true;
query.outFields = [
"POSTCODE"
];
on(dom.byId("execute"), "click", execute);
function execute() {
//
query.text = dom.byId("Postcode").value;
queryTask.execute(query, showResults);
};
function showResults(results) {
var resultItems = [];
var inBuffer = [];
var resultCount = results.features.length;
for (var i = 0; i < resultCount; i++) {
inBuffer.push(results.features[i].geometry);
var featureAttributes = results.features[i].attributes;
var graphic = results.features[i];
graphic.setSymbol(symbol);
map.graphics.add(graphic);
var strNum = 100;
var newExtent = graphic.geometry.getExtent();
newExtent.xmin = newExtent.xmin - strNum;
newExtent.ymin = newExtent.ymin - strNum;
newExtent.xmax = newExtent.xmax + strNum;
newExtent.ymax = newExtent.ymax + strNum;
map.setExtent(newExtent);
for (var attr in featureAttributes){
resultItems.push("<b>" + attr + ":</b> " + featureAttributes[attr] + "<br>");
}
resultItems.push("<br>");
}
var query2 = new Query();
query2.geometry = geometryEngine.union(inBuffer);
query2.returnGeometry = false;
query2.outFields = ["NAME", "OBJECTID"];
var queryTask2 = new QueryTask("http://rest/services/live/SEARCH/MapServer/15");
//resultItems.push("Before process");
queryTask2.execute(query2, function (results2) {
//resultItems.push("Before");
for (var j = 0; j < results2.features.length; j++) {
resultItems.push("<b>Local Authority:</b> " + results2.features[j].attributes.NAME + "<br/>" + "<b>Object id:</b>" + results2.features[j].attributes.OBJECTID + "<br/>");
}
//resultItems.push("After");
var lstr = "";
for (var j = 2; j <= resultItems.length; j++) {
lstr = lstr + resultItems[j] + "" + j.toString();
}
dom.byId("info").innerHTML = lstr;
});
这是JSON如何构建的一个例子:
{ "Local authority": {
"objectid": "1",
"name": "Kent",
"service": [
"Libraries": "url",
"Bins": "url",
"Dog walking": "url"
]
},
"objectid": "2",
"name": "Devon",
"service": [
"Libraries": "url",
"Bins": "url",
"Dog walking": "url"
]
}
我希望有人可以提供帮助 - 花了一整天时间,我无法解决这个问题。谢谢。