2017-05-22 141 views
0

我有一個查詢SharePoint列表的JavaScript文件。列類型是一個名爲Devicetype的Choice列,而不是返回信息列表,它返回[object Object],如屏幕截圖所示。Javascript查詢返回'[object Object]'

我想知道如果它的變種查詢字符串?

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

它將結果返回到我在JavaScript下包含的HTML文件。

enter image description here

function getDeviceDetails() { 
    var txtTitle = ""; 
    var txtOverview = ""; 
    //var txtAccessories = ""; 
    var txtDeviceType = ""; 
    var tempLCS2 = ""; 
    var query = "http://collaboration-dev.norgine.com/sites/it/SystemInventory/_vti_bin/listdata.svc/Devices?$expand=LifeCycleStatus&$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 //moment 
     //var LifeCycleStart = moment(item.DeviceAvailableFrom, "MM-DD-YYYY"); 

     var date = item.DeviceAvailableFrom; 
     //var LifeCycleStart = moment(date).format('DD-MM-YYYY'); 

     var LifeCycleStart = String.format('{0:dd}-{0:MM}-{0:yyyy}', new Date(item.DeviceAvailableFrom)); 
     //var LifeCycleStart=new Date(); 
     //LifeCycleStart.toString('dddd,MMM,yyyy'); 
     var LifeCycleStatus = item.LifeCycleStatusValue; 
     var DeviceOverView = item.Description; 
     //var AccessDetails = item.Accessorries; 
     var DeviceKind = item.Devicetype; 
     txtTitle = "<p>" + LifeCycleStart + "</p><p>" + LifeCycleStatus + "</p>"; 
     txtOverview = "<p>" + DeviceOverView + "</p>"; 
     //txtAccessories = "<p>" + Accessorries + "</p>"; 
     txtDeviceType = "<p>" + DeviceKind + "</p>"; 
    }); 
    $('#devicedetails').append($(txtTitle)); //moment 
    $('#deviceoverview').append($(txtOverview)); 
    $('#devicekind').append($(txtDeviceType)); 
    //$('#deviceacc').append($(txtAccessories)); 
    }); 

    call.fail(function(jqXHR, textStatus, errorThrown) { 
    alert("Error retrieving data: " + jqXHR.responseText); 
    }); 
} 
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 
<head> 
    <script src="/jquery-1.10.1.min.js"></script> 
    <script src="/it/SystemInventory/SiteAssets/scripts/moment.min.js"></script> 
    <script src="/sites/it/SystemInventory/SiteAssets/getDevices.js"></script> 
    <script src="/sites/it/SystemInventory/SiteAssets/getDeviceDetails.js"></script> 
    <script src="/sites/it/SystemInventory/SiteAssets/getDeviceKnownIssues.js"></script> 
    <script type="text/javascript"> 
    function parseQueryString(queryString) { 
     var params = {}, 
     queries, temp, i, l; 
     queries = queryString.split("&"); 
     for (i = 0, l = queries.length; i < l; i++) { 
     temp = queries[i].split('='); 
     params[temp[0]] = temp[1]; 
     } 
     return params; 
    } 

    $(document).ready(function() { 
     function getDeviceID() { 
     if (typeof parseQueryString === "function") { 
      if (window.location.href.indexOf("?") >= 0) { 
      var qs = parseQueryString(window.location.href.split("?")[1]) 
      window.DeviceId = qs.did; 
      getDeviceDetails(); 
      getDeviceKnownIssues(); 
      } 
     } 
     } 

     getDeviceID(); 
     getDevices(); 
    }); 
    </script> 
</head> 
<style type="text/css"> 
    .tg { 
    border-collapse: collapse; 
    border-spacing: 0; 
    } 

    .tg td { 
    font-family: Arial, sans-serif; 
    font-size: 14px; 
    padding: 10px 5px; 
    border- style: solid; 
    border-width: 1px; 
    overflow: hidden; 
    word-break: normal; 
    } 

    .tg .tg-yw4l { 
    vertical-align: top 
    } 
</style> 
<table class="tg"> 
    <tr> 
    <td class="tg-yw4l"> 
     <h1>Devices</h1> 
     <div id="devices"> 
     </div> 
    </td> 
    <td class="tg-yw4l"> 
     <h1>Device Details</h1> 
     <div id="devicedetails"> 
     </div> 
    </td> 
    <td class="tg-yw4l"> 
     <h1>Device Overview</h1> 
     <div id="deviceoverview"> 
     <div id="devicekind"> 
     </div> 
    </td> 
    </tr> 
</table> 

<table class="tg"> 
    <tr> 
    <td class="tg-yw4l"> 
     <h1>Accessories</h1> 
     <div id="deviceacc"> 
     </div> 
    </td> 
    <td class="tg-yw4l"> 
     <h1>Typical Usage</h1> 
     <div id=" "> 
     </div> 
    </td> 
    <td class="tg-yw4l"> 
     <h1>Another Table</h1> 
     <div id=" "> 
     </div> 
    </td> 
    </tr> 
</table> 

<!--[if gte mso 9]> 
    <xml> 
    <mso:CustomDocumentProperties> 
    <mso:_dlc_DocId msdt:dt="string">ITDOCUMENTS-135-47</mso:_dlc_DocId> 
    <mso:_dlc_DocIdItemGuid msdt:dt="string">1d6007ea-9e58-4298-b2d6- 
    9196e2678ea3</mso:_dlc_DocIdItemGuid> 

    <mso:_dlc_DocIdUrl msdt:dt="string">http://collaboration- 
     dev.norgine.com/sites/it/SystemInventory/_layouts/DocIdRedir.aspx? 
     ID=ITDOCUMENTS-135-47, ITDOCUMENTS-135-47</mso:_dlc_DocIdUrl> 
    </mso:CustomDocumentProperties> 
    </xml> 
<![endif]--> 
+0

'$('#devicedetails')。append(txtTitle); // moment $('#deviceoverview')。append(txtOverview); $('#devicekind')。append(txtDeviceType);'你應該使用'$()。append()'而不需要$ -operator作爲參數。 – noChance

+0

對,所以行應該是:$('#devicekind')。append); ? – Dazza

+0

只需$('#devicekind')。append(txtDeviceType);'因爲'txtDeviceType'是一個包含HTML屬性的字符串。因此,只要變量本身傳遞給jQuery對象的附加功能 – noChance

回答

0

它的東西做的內容類型。如果我將列從Drop Down更改爲Free Text並更改$('#devicekind')。append(txtDeviceType [0]); to $('#devicekind')。append(txtDeviceType);它會返回正確的結果。

相關問題