如何使用ecmascript或SPServices获取人员或组类型的SharePoint列表字段值?

时间:2015-05-06 11:38:57

标签: javascript sharepoint-2013 ecmascript-6 spservices

以下是我的代码......

function retrieveListItems() {
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('list name');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'ID\'/>' + < Value Type = \'Integer\'>413</Value></Eq></Where></Query></View>');
    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();
        listItemInfo += 'Title: ' + oListItem.get_item('Writer').get_lookupValue();
    }
    alert(listItemInfo.toString());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

我甚至尝试使用oListItem.get_item('Writer').get_title(),但它无效... 有时它会返回undefined ...... 请帮忙..

1 个答案:

答案 0 :(得分:0)

如果您要查找列表项'Created By'值,请使用'Author'代替'Writer',或者如果您想要'Modified By'值,请使用'Editor'而不是'Writer'。