SP.Taxonomy.TaxonomySession.getTaxonomySession
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script><script type="text/javascript" src="_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="_layouts/15/sp.js"></script><script type="text/javascript" src="_layouts/15/SP.Taxonomy.js"></script>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script><script type="text/javascript" src="_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="_layouts/15/sp.js"></script><script type="text/javascript" src="_layouts/15/SP.Taxonomy.js"></script>
<script type="text/javascript">// <![CDATA[
var context = new SP.ClientContext.get_current();
SP.SOD.executeFunc("sp.js", 'SP.ClientContext', function () {
AllTerms()
});
var term;
var terms;
var termGUIDs = new Array();
var termIDs = new Array();
var context = new SP.ClientContext.get_current();
SP.SOD.executeFunc("sp.js", 'SP.ClientContext', function () {
AllTerms()
});
var term;
var terms;
var termGUIDs = new Array();
var termIDs = new Array();
function AllTerms() {
termGUIDs = new Array();
termIDs = new Array();
termGUIDs = new Array();
termIDs = new Array();
//Current Taxonomy Session
var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStores = taxonomySession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStore = termStores.getByName("Taxonomy_AR432SAsZfzLjMeFcL4tw==");
//GUID of Term Set from which to get the Terms.
var termGroup = termStore.getGroup(GUID);
var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStores = taxonomySession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStore = termStores.getByName("Taxonomy_AR432SAsZfzLjMeFcL4tw==");
//GUID of Term Set from which to get the Terms.
var termGroup = termStore.getGroup(GUID);
var termSet = termGroup.get_termSets().getByName("Child");
terms = termSet.getAllTerms();
context.load(terms);
context.executeQueryAsync(
Function.createDelegate(this, getTermsComplete),
function (sender, args) { alert("Get Terms: " + args.get_message()); }
);
}
context.executeQueryAsync(
Function.createDelegate(this, getTermsComplete),
function (sender, args) { alert("Get Terms: " + args.get_message()); }
);
}
function getTermsComplete() {
var html = "
<ul>";
var termEnumerator = terms.getEnumerator();
//var termPath = term.get_pathOfTerm();
while (termEnumerator.moveNext()) {
var currentTerm = termEnumerator.get_current();
var currentTermPath = currentTerm.get_pathOfTerm();
var currentGuid = currentTerm.get_id().toString();
var html = "
<ul>";
var termEnumerator = terms.getEnumerator();
//var termPath = term.get_pathOfTerm();
while (termEnumerator.moveNext()) {
var currentTerm = termEnumerator.get_current();
var currentTermPath = currentTerm.get_pathOfTerm();
var currentGuid = currentTerm.get_id().toString();
html += "
<li>" + currentTerm.get_name() + " [" + currentTerm.get_pathOfTerm() + "]</li>
<li>" + currentTerm.get_name() + " [" + currentTerm.get_pathOfTerm() + "]</li>
";
html += "
<li>" + currentTerm.get_id().toString() + "</li>
html += "
<li>" + currentTerm.get_id().toString() + "</li>
";
}
html += "</ul>
html += "</ul>
";
//Output interim details of what terms are this node or subnodes
var div = document.getElementById('outputDiv').innerHTML = html;
}
//Output interim details of what terms are this node or subnodes
var div = document.getElementById('outputDiv').innerHTML = html;
}
// ]]></script>
<label id="outputDiv"></label>
<label id="outputDiv"></label>