返回带有变量“未定义”的Javascript文件
我有一个JavaScript文件,它工作得很好,只是它没有返回一个字段。它们都来自SharePoint列表,显示“未定义”,但我想我一开始就定义了它 返回的信息显示在HTML pafe上 我遇到问题的变量是'var txtFutureInfo=;'?其他一切都很好。感谢您的帮助。下面是JavaScript,它后来被称为DeviceInformation返回带有变量“未定义”的Javascript文件,javascript,json,Javascript,Json,我有一个JavaScript文件,它工作得很好,只是它没有返回一个字段。它们都来自SharePoint列表,显示“未定义”,但我想我一开始就定义了它 返回的信息显示在HTML pafe上 我遇到问题的变量是'var txtFutureInfo=;'?其他一切都很好。感谢您的帮助。下面是JavaScript,它后来被称为DeviceInformation function getDeviceDetails() { var txtTitle = ""; var txtName = ""; var t
function getDeviceDetails() {
var txtTitle = "";
var txtName = "";
var txtOverview = "";
var txtAccessories = "";
var txtDevicetype = "";
var txtTypicalDeviceUsage ="";
var txtKnownSystemIssues ="";
var txtTrafficlight = "";
var imgDevicePicture = "";
var tempLCS2 = "";
var txtfurtherinfo ="";
var HTML = "<h3>Desktop</h3>";
var Laptop = "Y"
var Tabs="Y"
var query = "http://example.com/sites/it/ITInfrastructure/_vti_bin/listdata.svc/Devices?$expand=Priority&$filter=Id eq " + window.DeviceId + "";
var call = $.ajax({
url: query,
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
});
call.done(function (data,textStatus, jqXHR){
$.each(data.d.results, function(index, item) {
var tempID = item.Id;
var NameofDevice = item.Title;
var tempTitle = item.Title;
var DeviceOverView = item.Description;
var AccessDetails = item.Accessories;
var DeviceKind = item.DevicetypeValue;
var Usage = item.TypicalUsage;
var DevicePriority = item.PriorityValue;
var DeviceImage = item.DeviceImage;
var DeviceInformation = item.furtherinfo;
txtTitle = "<p>" + NameofDevice + "<p>";
txtName = "<p>" + NameofDevice + "</p>" + DeviceKind + "</p>";
txtOverview = "<p>" + DeviceOverView + "</p>";
txtAccessories = "<p>" + AccessDetails + "</p>";
txtDevicetype = "<p>" + DeviceKind + "</p>";
txtTypicalDeviceUsage = "<p>" + Usage + "</p>";
txtTrafficlight = "<p>" + DevicePriority + "</p>";
txtfurtherinfo ="<p>" + DeviceInformation + "</p>";
imgDevicePicture = "<img src='" + DeviceImage + "'>";
});
$('#devicedetails').append($(txtTitle));
$('#deviceoverview').append($(txtOverview));
$('#devicetitle').append($(txtTitle));
$('devicename').append(txtName);
$('#devicekind').append(txtDevicetype);
$('#deviceacc').append(txtAccessories);
$('#deviceuse').append(txtTypicalDeviceUsage);
$('#devicestatus').append(txtTrafficlight);
$('#furtherinfo').append(txtfurtherinfo);
$('#imageContainer').append("<img src='/sites/IT/ITInfrastructure/SiteAssets/"+txtTrafficlight.replace(/<[^>]*>/g, '')+".png' />");
$('.deviceimage').append(imgDevicePicture);
});
call.fail(function (jqXHR,textStatus,errorThrown){
alert("Error retrieving data: " + jqXHR.responseText);
});
}
在javascript中,很多情况下,当您试图访问范围中未定义的信息时,会出现未定义的情况。 您的项目变量可能没有任何名为“进一步信息”的成员变量。
根据其他成员变量的符号,它可以被称为进一步信息,进一步信息,或者类似的问题。问题出在哪里?您是否查看了HTTP请求的实际响应,以验证每个项是否确实包含一个FutureInfo属性?这真的是产生问题的代码的最小示例吗?您是否希望getDeviceDetails返回未定义的内容以外的内容?在美化您的代码并删除所有非必需的代码之后,我可以看到您在函数内部进行了异步Ajax调用,从调用getDecviceDetails的角度来看,这可能会在将来某个时候发生。每个项变量都会向HTML表返回一个结果。例如:var txtOverview=;var DeviceOverView=项目说明;txtOverview=+设备概览+;$'deviceoverview'。追加$txtOverview;在HTML表中使用deviceoverview的div标记,该表显示在SharePoint字段中输入的笔记本电脑规格。我想要var DeviceInformation=item.furthinfo;返回在新SharePoint字段中输入的多行文本,而不是未定义的文本。