对SharePoint列表项的Javascript查询返回相同的结果

时间:2017-08-09 09:11:21

标签: javascript json sharepoint-2010

我尝试使用JavaScript查询显示SharePoint列表的“标题”字段,但无论我点击哪个链接,它都会保持返回相同的结果。如下所示,如果我点击联想T470'它应该在图像上方显示出来的东西,但它一直在显示联想X1 Carbon'。

Service Catalogue Results

如果我更改了代码:

var DeviceName = result.Title;

为:

var DeviceName = item.Title;

它回来未定义。有任何想法吗?完整代码如下:

function getDevices() {
var txtTitle = "";
var txtTitleName = "";
//var txtDeviceType = "";


  var query  = "http://example.com/sites/it/ITInfrastructure/_vti_bin/listdata.svc/Devices?select=ID,Title";





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 (i, result) {

        var tempID = result.Id;
        var tempTitle = result.Title;
        var DeviceName = result.Title;

        txtTitle = txtTitle + "<p><a href='/sites/it/ITInfrastructure/SitePages/Service%20Catalogue%20Devices.aspx?did=" + tempID + "'>" + tempTitle + "</a></p>";
        txtTitleName ="<p>" + DeviceName + "</p>";



    });
    $('#devices').append($(txtTitle));
    $('#devicetitle').append(txtTitleName);


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

0 个答案:

没有答案