如何使用JSOM加载SharePoint Online Termset?

时间:2017-08-08 16:15:06

标签: jquery sharepoint-online sharepoint-jsom

我想使用JSOM检索SharePoint Online termset。我有一个脚本,但是,当DOM准备就绪时,它不会自动加载termset,我注意到在检索termsets之前我必须在浏览器上进行硬刷新(crtl + F5)。

我的代码:

 <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>

<script type="text/javascript">
"use strict";
$(document).ready(function () {  

    alert("I am ready");
    SP.SOD.executeFunc('sp.runtime.js', false, function () {

            SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
                SP.SOD.registerSod('sp.taxonomy.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.taxonomy.js'));
                //loads sp.taxonomy.js file
                SP.SOD.executeFunc('sp.taxonomy.js', false, GetTermsFromTaxonomyStore);
            });

        });
function GetTermsFromTaxonomyStore() {
    var termSetName1 = "Technology";
    var locale1 = 1033; // your locale. Here is English

    var clientContext1  = SP.ClientContext.get_current();
    var taxonomySession1 = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext1);
    var termStore1 = taxonomySession1.getDefaultSiteCollectionTermStore();
    var termSets1 = termStore1.getTermSetsByName(termSetName1, locale1);
    var termSet1 = termSets1.getByName(termSetName1);
    var terms1 = termSet1.getAllTerms();

    clientContext1.load(taxonomySession1);
    clientContext1.load(termStore1);
    clientContext1.load(termSet1);
    clientContext1.load(terms1);

    clientContext1.executeQueryAsync(function onSuccess1() {
        var enumerator1 = terms1.getEnumerator();

        while (enumerator1.moveNext()) {
            var spTerm1 = enumerator1.get_current();
            var spTerm1Val=spTerm1.get_name();
            console.log(spTerm1Val);


        }



    }, function onFailure1(args) {
        alert('Error: '+args.get_message());
    });

}

 });
</script>

0 个答案:

没有答案