我们有
我尝试创建一个JavaScript控件来可视化库中的文件夹结构。但我无法获得自定义“DisplayName”字段值
this.clientContext = SP.ClientContext.get_current();
var web = this.clientContext.get_web();
this.clientContext.load(web);
this.clientContext.executeQueryAsync(function(sender, args) {
for (var i = 0; i < this.topLevelFoldersUrl.length; i++) {
var contextParams = {};
contextParams.folderUrl = web.get_serverRelativeUrl() + "/" + this.topLevelFoldersUrl[i];
// folder
contextParams.topLevelFolder = web.getFolderByServerRelativeUrl(contextParams.folderUrl);
this.clientContext.load(contextParams.topLevelFolder, 'Include(DisplayName)');
// folder list item
contextParams.folderListItem = contextParams.topLevelFolder.get_listItemAllFields();
this.clientContext.load(contextParams.folderListItem);
// subfolders
contextParams.folderCollection = contextParams.topLevelFolder.get_folders();
this.clientContext.load(contextParams.folderCollection);
this.clientContext.executeQueryAsync(
function (sender, args) {
var folderName = contextParams.topLevelFolder.get_name();
// EXCEPTION goes here: "property has not been initialized"
var folderDisplayName = contextParams.folderListItem.get_item("DisplayName");
// visualization code...
},
this.onQueryFailed
);
}
}, this.onQueryFailed);
是否有特殊技术来获取文件夹自定义字段?我已经使用Google搜索所有代码示例来获取列表项及其自定义字段,但样本在我的情况下不起作用。
答案 0 :(得分:1)
&#34; DisplayName的&#34;似乎是SharePoint 2013 JSOM中的保留标识符。将字段的名称更改为&#34; ShownName&#34;我的代码工作:
this.clientContext = SP.ClientContext.get_current();
var web = this.clientContext.get_web();
this.clientContext.load(web);
this.clientContext.executeQueryAsync(function (sender, args) {
for (var i = 0; i < this.topLevelFoldersUrl.length; i++) {
var contextParams = {};
contextParams.folderUrl = web.get_serverRelativeUrl() + "/" + this.topLevelFoldersUrl[i];
contextParams.topLevelFolder = web.getFolderByServerRelativeUrl(contextParams.folderUrl);
this.clientContext.load(contextParams.topLevelFolder);
contextParams.folderListItem = contextParams.topLevelFolder.get_listItemAllFields();
this.clientContext.load(contextParams.folderListItem, 'ShownName');
contextParams.folderCollection = contextParams.topLevelFolder.get_folders();
this.clientContext.load(contextParams.folderCollection);
this.clientContext.executeQueryAsync(
function(sender, args) {
var folderName = folder.get_name();
var folderDisplayName = folderItem.get_item("ShownName");
// visualization code...
},
this.onQueryFailed
);
}
}, this.onQueryFailed);