ECMA script Error: The collection has not been initialized

坚强是说给别人听的谎言 提交于 2019-12-22 10:37:57

问题


I am getting this error while using querying a SharePoint list (2010) through JQuery The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

I am looping through all the options in html select element and querying SharePoint list.

     $("#IdeasStatus option").each(function()
    {
        statusCount = statusCount + 1;
        lstStatus.push($(this).val());            
    });

    for (var i = 0; i < lstStatus.length; i++) {
         *****Some Code*********
       retItems = spList.getItems(caml);                       
       spContext.load(retItems);
      spContext.executeQueryAsync(onCategorySuccess, onCategoryFail);}

I am getting error in below function

    function onCategorySuccess(sender, args) {
    executionCount++;
    $('input[id$=hidChartParam1]').val($('input[id$=hidChartParam1]').attr('value') + ',' + status);
    $('input[id$=hidChartParam2]').val($('input[id$=hidChartParam2]').attr('value') + ',' + retItems.get_count());
    if (executionCount == statusCount) {
        FillPieChart();
    }
}

error is thrown while fetching the count retItems.get_count() which I believe is because same variable name (retItems) is used while looping and making multiple async calls?

Please suggest what shall I do?


回答1:


Have You call onCategorySuccess elsewhere? It looks like you are in the onCategorySuccess before actually fill in retItems with values.




回答2:


i believe that at some point before calling spList.getItems you should load to the context the spList



来源:https://stackoverflow.com/questions/15022963/ecma-script-error-the-collection-has-not-been-initialized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!