1
我想打印從我的實體中檢索到的值在警報消息中。我將值存儲在relatedproduct數組中我想打印這些值。當它試圖打印它們時給出不確定message.Plz幫我從動態Crm使用odata和jquery實體檢索記錄
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);
}
}
@Mike_Matthews_II函數聲明的排序並不重要,因爲腳本被解釋THEN執行。即使GetRecords是一個自動執行的函數(它不是),它仍然是有效的。孤立的這段代碼除了聲明4個全局作用域函數和一個數組之外,實際上不會做任何事情。這裏有一個示例小提琴http://jsfiddle.net/DkSG2/ – 2013-03-23 13:38:32
@ user2165650請提供關於在調試器中看到的行爲的一些信息?我假設你已經嘗試過使用瀏覽器開發工具進行調試,而不是隻是拋出它,讓我們爲你解決這個問題? – 2013-03-23 13:49:26
@DazLewis嗯,我錯了。感謝您糾正我的假博文。我現在要刪除我的錯誤信息。 – 2013-03-25 20:50:00