为什么我总是得到属性或字段尚未初始化

Why do i always get The property or field has not been initialized?

本文关键字:字段 初始化 属性 为什么      更新时间:2024-06-26

你好,我尝试用特定字段填充数组。但我总是得到:The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.我在Sharepoint 2013上,我使用Sharepoint的内部名称。我认为我的Caml查询有问题。

这是我使用的代码:

 function retrieveListItems(siteUrl) {
        var clientContext = new SP.ClientContext(siteUrl);
        var oList = clientContext.get_web().get_lists().getByTitle('MatrixFiles');
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('<View><ViewFields><FieldRef Name="LinkFilename" /><FieldRef Name="WebCountry" /><FieldRef Name="WebDepartment" /><FieldRef Name="FileLeafRef" /></ViewFields><Query><OrderBy><FieldRef Name="LinkFilename" /></OrderBy></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 array = [];
    var listItemEnumerator = this.collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        console.log(oListItem);
        array.push(oListItem);

    }
    alert(oListItem.get_item('LinkFilename'));

}

奇怪的是,数组中充满了SPListItems,但当我尝试在警报中使用特定字段时,就会发生错误。不知道为什么。。。。

任何帮助都将是伟大的,谢谢你的时间。

BTW我为此使用了SP凸轮查询帮助程序。

尝试使用FileLeafRef。LinkFilename是一个不起作用的计算字段。

msdn-无法使用LinkFileName 搜索列表

我想发生这个错误是因为sp.js脚本尚未加载。

尝试:

  //Insert this right after your opening script tag
   ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
   //then your function as written above   
   function retrieveListItems(siteUrl) { etc...};

此外,这个答案可能会有所帮助:SharePoint 2013在整个页面加载后添加javascript