嗨我正在更新在object中创建的keyIndex数组,而我将数组添加到URL则不起作用:
我的代码:
var dataObject = {
Indices: {
subIndex: {
keyIndex: [], //this is not updating in baseURL 'keyIndex'
method: 'GetCCINationalIndicesData',
baseURL: 'http://107.20.173.235/BlufinAPI/Service/ConsumerConfidenceIndex.svc/GetCCINationalIndicesData?InputJSON={"IndexID":"' + keyIndex + '","FromMonth":"10","FromYear":"2011","ToMonth":"3","ToYear":"2012"}'
}
},
Geography: {
0: '1',
tiers: {
method: 'GetCCITierIndicesData'
},
regions: {
method: 'GetCCIRegionIndicesData'
},
city: {
method: 'GetCCICityIndicesData'
}
},
Demographics: {}
}
有什么不对吗?
答案 0 :(得分:2)
这是因为keyIndex
仅在创建baseURL
字符串时被评估一次。
你可以改为baseURL
一个函数......
baseURL:function() {
return 'http://107.20.173.235/BlufinAPI/Service/ConsumerConfidenceIndex.svc/GetCCINationalIndicesData?InputJSON={"IndexID":"' +
this.keyIndex +
'","FromMonth":"10","FromYear":"2011","ToMonth":"3","ToYear":"2012"}';
}
然后把它称为函数......
dataObject.Indices.subIndex.baseURL();
虽然原始keyIndex
首先不是对象属性的引用。
这与jQuery无关。