指定的参数超出了有效值的范围。参数名称:index

时间:2015-01-08 14:06:05

标签: javascript jquery sharepoint

我有以下javascript代码,必须从sharepoint托管元数据存储中加载termset。 代码工作正常,直到星期一,突然停止处理标题上的错误。

我只使用console.log更改了executequeryasync的内容,但仍然有错误。

我已逐行调试execGetTermIds,并且没有任何行抛出异常

function GetTermsDataFromTaxonomy(){
    //Current Context
    var context = SP.ClientContext.get_current();           
    //Current Taxonomy Session
    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);           
    //Term Stores
    var termStores = taxSession.get_termStores();           
    //Name of the Term Store from which to get the Terms.
    var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");          
    //GUID of Term Set from which to get the Terms.
    var termSet = termStore.getTermSet("31da4bc1-6429-499a-9d5e-be5e18b13c87");         
    var terms = termSet.getAllTerms();      
    var list;   
    var p = execGetTermIDs();
    p.done(function(result) {

        context.load(terms);

        context.executeQueryAsync(function(){   
            console.log("hola");
        },
            function(sender,args){          
              console.log(args.get_message());              
        });
    });
    p.fail(function(result) {
        // result is a string because that is what we passed to reject()!
        var error = result;
        console.log(error);
    });

}

function sortTermsFromTree (tree) {
    if (tree.children.length && tree.term.get_customSortOrder) {
        var sortOrder = null;

        if (tree.term.get_customSortOrder()) {
            sortOrder = tree.term.get_customSortOrder();
        }

        // If not null, the custom sort order is a string of GUIDs, delimited by a :
        if (sortOrder) {
            sortOrder = sortOrder.split(':');

            tree.children.sort(function (a, b) {
                var indexA = sortOrder.indexOf(a.guid);
                var indexB = sortOrder.indexOf(b.guid);

                if (indexA > indexB) {
                    return 1;
                } else if (indexA < indexB) {
                    return -1;
                }

                return 0;
            });
        }
        // If null, terms are just sorted alphabetically
        else {
            tree.children.sort(function (a, b) {
                if (a.title > b.title) {
                    return 1;
                } else if (a.title < b.title) {
                    return -1;
                }

                return 0;
            });
        }
    }

    for (var i = 0; i < tree.children.length; i++) {
        tree.children[i] = sortTermsFromTree(tree.children[i]);
    }

    return tree;
}

function execGetTermIDs(){
    var d = $.Deferred();
    var q = "<View><Query><Where></Where></Query></View>";
    var context = new SP.ClientContext(siteUrl);
    var oList = context.get_web().get_lists().getByTitle('TaxonomyHiddenList');
    var camlQuery = SP.CamlQuery.createAllItemsQuery();
    var collTermListItem = oList.getItems(camlQuery);
    context.load(collTermListItem);
    var o = {d: d, collTermListItem:collTermListItem};
    context.executeQueryAsync(
    Function.createDelegate(o, getTermIDsComplete),
    Function.createDelegate(o, failCallback)
    );
    return d.promise();
}

function getTermIDsComplete()
{
    var listItemEnumerator = this.collTermListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        termIDs[oListItem.get_fieldValues().Title] = oListItem.get_id();
    }
    this.d.resolve(termIDs);
}

function failCallback() {
    this.d.reject("something bad happened");
}

1 个答案:

答案 0 :(得分:1)

omg,我发现了错误,我无法找到解释,希望微软的某个人能告诉我。

这一行:

 var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");   

我们注意到名称现在不同了,它有一个不同的guid,但我们作为客户不能更改该名称,所以唯一的原因是微软为我们改变它,因为它在星期一工作。

更新:我用以下内容更改了该行:

termStore = session.getDefaultSiteCollectionTermStore();

以避免将来发生。