【问题标题】:Ajax - Parse oData ResponseAjax - 解析 oData 响应
【发布时间】:2018-05-04 15:17:01
【问题描述】:

我有一个从 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/$metadata#WEB_V_CIVIC_ADDRESS/AValues.Classes.Entities.AccountAddress","value":[ { "@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”?

谢谢。

【问题讨论】:

    标签: ajax odata


    【解决方案1】:

    我知道了,需要改成 response($.map(data.value, function (item)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 2019-05-15
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多