0

Just when I think I've got he hang of identifying an element in an object, I run into a scenario that I cannot seem to get the value I want.

This part works and the data returned is correct: I have a map and when I attempt to identify a building on the map, I receive the following json object (this has been shortened for readability but in real life, its properly formatted): The function MapClick(queryResults) is called when the map is clicked.

dojo.io.script.jsonp_dojoIoScript19._jsonpCallback({
"results": [
    {
        "layerId": 5,
        "layerName": "Building",
        "value": "Name of item clicked",
        "displayFieldName": "name",
        "attributes": {
            "ID": "123",
            "name": "Name of item clicked",
            "Variable1": "Some bit of information",
            "Variable2": "Some other bit of information",
            ...
            ...

All I'm trying to do is return either the results[0].value OR results[0].attributes.name which in this example should bring back "Name of item clicked". The layerId, layerName, value, and displayFieldName are the "common most accessed data" so they are returned but the same information is also found within the attributes.

I've tried console.log(results[1].attributes.name); and console.log(results) with no success.

4

1 回答 1

0

原来处理 MapClicked 的函数的名称是 queryResults 是需要的,所以正确的答案是: queryResults[0].value当你看到开括号时[,你可以确定你需要[一些数字](例如queryResults[0].valuequeryResults[99].someothervariable。或者至少我认为这是一个正确的陈述.

于 2014-02-24T17:49:32.093 回答