将SharePoint术语集绑定到Bootstrap multiselect

时间:2017-08-04 08:08:57

标签: twitter-bootstrap sharepoint sharepoint-online bootstrap-multiselect sharepoint-jsom

我正在尝试将使用JSOM检索到的SharePoint在线术语绑定到jquery multiselect下拉控件,但运气不足以下是获取术语并绑定到多选控件的当前代码。 但是,当页面加载到术语时绑定到多选控件

 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
<select id="parent_task" multiple="multiple"></select>
<script type="text/javascript">
$(document).ready(function () {        


        //This makes sure all necessary Js files are loaded before you call taxonomy store
        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);

      $("#parent_task").multiselect({ includeSelectAllOption: true });
            });

        });


    });
    //This method uses the Taxonomy client side object calls to get the terms 
    function GetTermsFromTaxonomyStore() {

       var termSetName = "ABB Tasks";
var locale = 1033; // your locale. Here is English

var clientContext  = SP.ClientContext.get_current();
var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext);
var termStore = taxonomySession.getDefaultSiteCollectionTermStore();
var termSets = termStore.getTermSetsByName(termSetName, locale);
var termSet = termSets.getByName(termSetName);
var terms = termSet.getAllTerms();

clientContext.load(taxonomySession);
clientContext.load(termStore);
clientContext.load(termSet);
clientContext.load(terms);

clientContext.executeQueryAsync(function onSuccess() {
    var enumerator = terms.getEnumerator();

    while (enumerator.moveNext()) {
        var spTerm = enumerator.get_current();
        var name = spTerm.get_name();
        var id = spTerm.get_id();
      $('#parent_task').append('<option value = "'+name +'">' +name + '</option>');

    }



}, function onFailure(args) {
    alert('Error: '+args.get_message());
});
    }
</script>

0 个答案:

没有答案