我想在警报消息中打印从我的实体检索到的值。我将值存储在relatedproduct数组中我想打印这些值。当它尝试打印它们时,它会给出未定义的消息.Plz帮助我
relatedProducts = [];
function onload() {
var oDataUri="https://yanceyworksllc.crm.dynamics.com/xrmservices/2011/OrganizationData.svc/ProductSet?$select=new_price,ProductId&$filter=new_TaxInformation/Value eq 1";
GetRecords(oDataUri);
var totalRecords = relatedProducts .length;
}
function GetRecords(url) {
jQuery.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: url,
async: false,
beforeSend: function (XMLHttpRequest) {
var x= XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
if (data && data.d != null && data.d.results != null) {
AddRecordsToArray(data.d.results);
FetchRecordsCallBack(data.d);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
// FetchRecordsCallBack(data.d);
alert("Error : has occured during retrieval of the records ");
}
});
}
function AddRecordsToArray(records) {
for (var i = 0; i < records.length; i++) {
relatedProducts .push(records[i]);
alert(relatedProducts[i].Value) ;
}
}
function FetchRecordsCallBack(records) {
if (records.__next != null) {
var url = records.__next;
GetRecords(url);
}
}
答案 0 :(得分:0)
对OData调用进行故障排除的一种非常简单的方法是将URI复制到浏览器中并导航到该页面。如果它没有带您进入包含数据的页面,则表示您的uri错误。如果是,那么您正在错误地处理结果数据(即如果调试器在GetRecords中命中成功块,则AddRecordsToArray或FetchRecordsCallBack被破坏)。
旁注 - 我从未在“。[属性名称]”之前看过一个空格。这甚至是一个有效的JavaScript语法(如在您的相关产品.push或relatedProducts .length中)?