Javascript var query returning [object Object]

时间:2017-06-15 09:30:50

标签: javascript json sharepoint-2010

I've got a JavaScript file which is querying a SharePoint list. I'm querying two drop down lists. The first - LifeCycleStatus - comes back fine, but the Priority drop down comes back with screen grab [object OBJECT]. I think it has to do with the var query string. I've added the 'Priority' column to the var query but it doesn't seem to be making any difference

var query = "http://collaboration- 
   de.vxxx.com/sites/it/SystemInventory/_vti_bin/listdata.svc/Devices?$expand=LifeCycleStatus&Priority&$filter=Id eq " + window.DeviceId + "";

Full JavaScript below:

function getDeviceDetails() {
var txtTitle = "";
var txtOverview = "";
var txtAccessories = "";
var txtDevicetype = "";
var txtTypicalDeviceUsage ="";
var txtKnownSystemIssues ="";
var txtLifeCycles = "";
var txtTrafficlight = "";
    var tempLCS2 = "";

var query = "http://collaboration-dev.xxx/sites/it/SystemInventory/_vti_bin/listdata.svc/Devices?$expand=LifeCycleStatus&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 tempTitle = item.Title;




         var LifeCycleStart = item.DeviceAvailableFrom;



        var LifeCycleStatus = item.LifeCycleStatusValue;
        var DeviceOverView = item.Description;
        var AccessDetails = item.Accessories;
        var DeviceKind = item.Devicetype;
        var Usage = item.TypicalUsage;
        var DevicePriority = item.Priority;


        txtTitle = "<p>" + LifeCycleStart + "</p><p>" + LifeCycleStatus + "</p>";
        txtOverview = "<p>" + DeviceOverView + "</p>";
        txtAccessories = "<p>" + AccessDetails + "</p>";  
        txtDevicetype = "<p>" + DeviceKind  + "</p>";
        txtTypicalDeviceUsage = "<p>" + Usage + "</p>";
        txtTrafficlight = "<p>" + DevicePriority + "</p>";
       // txtKnownSystemIssues = "<p>" + KnownSystem + "</p>"
    });
    $('#devicedetails').append($(txtTitle));  
    $('#deviceoverview').append($(txtOverview));
    $('#devicekind').append(txtDevicetype);
    $('#deviceacc').append(txtAccessories);
    $('#deviceuse').append(txtTypicalDeviceUsage);
    $('#devicestatus').append(txtTrafficlight);

});





call.fail(function (jqXHR,textStatus,errorThrown){
    alert("Error retrieving data: " + jqXHR.responseText);
});

}

1 个答案:

答案 0 :(得分:0)

“Priority”和“LifeCycleStatus”包含一个对象。你可以使用调试器/控制台来查看对象是什么 - 我敢打赌它包含一个带有Value的字符串,以及值的内部ID,可能还有其他东西。将对象转换为字符串将返回“[object Object]”。

“优先级”和“LifeCycleStatus ”可能是值字符串的缩写。