0
我正在执行ajax调用并返回json格式的数据。使用来自另一个json对象的值填充json对象中的值
var ColorName = json.features[r].attributes.ColorName;
铬示出的值是 “0,255,0,204”,其对应于R,G,B,A(A是透明性) http://cl.ly/image/362k1K083o3c/ColorName%20value.jpg
我想做的是采取ColorName
并通过它到下面的对象:
var symbol = new SimpleMarkerSymbol({
"color": [ColorName],
"size": 12,
"angle": -30,
"xoffset": 0,
"yoffset": 0,
"type": "esriSMS",
"style": "esriSMSCircle",
"outline": {
"color": [0,0,0,255],
"width": 1,
"type": "esriSLS",
"style": "esriSLSSolid"
}
});
如果我硬编码值到对象,它的工作原理,但不是当我通过它,因为我已经如上图所示。我假设它是一个语法问题,因为其他所有工作都正常并且我没有收到任何错误。
============更新=================
这里是JSON格式的数据的一个片段如在可见火狐
{
"recordsReturned":"213",
"status":"pass",
"msg":"213 record(s) found",
"geometryType" : "esriGeometryPoint",
"spatialReference" : {
"wkid" : 4326
},
"features" : [
{
"attributes" : {
"name" : "XYZ Medical Center",
"statusID" : "1",
"NamedColor":"0,255,0,204"
},
"geometry" : {
"x" : -77.4954450,
"y" : 38.2170020
}
},
{
"attributes" : {
"name" : "ABC Medical Center",
"statusID" : "1",
"NamedColor":"0,255,0,204"
},
"geometry" : {
"x" : -76.3069444444,
"y" : 36.8447222222
}
},
这里是遍历返回的JSON对象的一个片段:
if (json.status == 'pass'){
for (var r = 0; r < json.recordsReturned;r=r+1){
var ColorName = json.features[r].attributes.NamedColor;
...
我希望这有助于...
告诉我们你是如何努力实现这一目标的。 “其他一切正常,没有错误”是没有用的,因为它涉及我们看不到的代码。 – Jon
马上行动起来... – HPWD
您确定这个值已经设定好了吗?你说的是ajax调用,你确定你正在设置ajax回调的值吗? –