我无法使用JSOM从SharePoint检索单个列表项

时间:2016-11-11 01:34:05

标签: javascript jquery sharepoint-2010 sharepoint-jsom

我使用caml和JSOM查询SharePoint 2010列表。我的查询将始终返回1项,但是当我删除While()循环时,没有任何反应。任何帮助将不胜感激。

function retrieveListItems() {
var clientContext = new SP.ClientContext();
var oList = clientContext.get_web().get_lists().getByTitle('Project');


    var prjQry = "<View><Query><Where><Eq><FieldRef Name='tID' /><Value Type='Text'>" + getQueryString('tID') + "</Value></Eq></Where></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Project_x0020_Number' /><FieldRef Name='Station_x0020_Name' /><FieldRef Name='VISN' /><FieldRef Name='Station_x0020_Number' /></ViewFields></View>";        

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(prjQry);
this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);

clientContext.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded),
    Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();

 while (listItemEnumerator.moveNext()) {

var oListItem = listItemEnumerator.get_current();

             $('#visn').val(oListItem.get_item('VISN'));
            $('#projTitle').val(oListItem.get_item('Title'));
            $('#station').val(oListItem.get_item('Station_x0020_Number'));
            $('#stationName').val(oListItem.get_item('Station_x0020_Name'));                                                
           $('#projNumber').val(oListItem.get_item('Project_x0020_Number'));   
}              

}

0 个答案:

没有答案