当前作者&编辑器在ListItem上可用,而不是该ListItem的SPFile对象。使用
SPListItem.get_Item("propertyName")
然后
get_lookupValue()
成功了。
以下代码段检索所有必需字段并返回延迟对象,以便可以链接调用:
getEvidenceDocuments = function (relativePath) {
var deferred = $.Deferred();
var clientContext = new SP.ClientContext("/documents");
var oList = clientContext.get_web().get_lists().getByTitle('Documents');
var query = SP.CamlQuery.createAllItemsQuery();
query.set_folderServerRelativeUrl(relativePath);
var allItems = oList.getItems(query);
clientContext.load(allItems, 'Include(Id, Title, ContentType, File, Author, Editor)');
clientContext.executeQueryAsync(Function.createDelegate(this, function () {
var ListEnumerator = allItems.getEnumerator();
var fileCollection = [];
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
var _contentType = currentItem.get_contentType();
if (_contentType.get_name() !== "Folder") {
var File = currentItem.get_file();
if (File !== null) {
var obj = {
id: currentItem.get_id(),
title: File.get_title(),
name: File.get_name(),
createdBy: currentItem.get_item("Author").get_lookupValue(),
created: File.get_timeCreated(),
// author: clientContext.load(File.get_author(), "Title"),
modifiedBy: currentItem.get_item("Editor").get_lookupValue(),
modified: File.get_timeLastModified()
};
fileCollection.push(obj);
}
}
}
deferred.resolve(fileCollection);
}), Function.createDelegate(this, function () {deferred.reject(); }));
return deferred.promise();
};