我有一个从REST API获取数据的ajax调用。
$.ajax({
url: "http://localhost:52139/odata/WEB_V_CIVIC_ADDRESS",
data: { enteredText: "'" + $('#addressTextField').val() + "'" },
type: "GET",
dataType: 'json',
ContentType: "application/json",
success: function (data) {
alert(JSON.stringify(data));
response($.map(data.accountaddressList, function (item) {
return {
item: item.civicaddress,
value: item.accountNumber,
label: item.civicaddress
}
}));
},
error: function (data, xml, errorThrown) {
alert('Error loading address list: ' + errorThrown);
}
});
从该通话中返回的odata看起来像:
{ “@ odata.context”: “http://localhost:52139/odata/ $元数据#WEB_V_CIVIC_ADDRESS / AValues.Classes.Entities.AccountAddress”, “值”:[ { “@ odata.type”:“#AValues.Classes.Entities.AccountAddress”,“accountNumber”:88887,“rowNumber”:0,“civicaddress”:“123 Fake St” },{ “@ odata.type”:“#AValues.Classes.Entities.AccountAddress”,“accountNumber”:88888,“rowNumber”:0,“civicaddress”:“321 Faker St” } ] }
所以当前代码在行上抛出一个'Undefined'错误:response($。map(data.accountaddressList,function(item){
如何将odata响应中每个值的'civicaddress'和'accountNumber'映射到'item'?
感谢。
答案 0 :(得分:0)
我知道了,需要将其更改为响应($。map(data.value,function(item)