This blog would show you the retrieve term store, the term group, the term set and the term via JavaScript
1. First, you need understand Managed Metadata Service, it used for storing Metadata, and has the database in dependent, Then all the site collection can reuse the data, such as Site column (Metadata field), Metadata Navigation and search data. Here are its construct:
Managed Metadata Service, term Stores, term Groups, term sets-
2. Second, since you retrieve metadata via JS, so SharePoint need provide the relevant API, here is the JS file provided By SharePoint OOB File:
SP. Runtime.js, Sp.js, SP. Taxonomy.jsmust make sure load those JS before your call the API (only SharePoint provide the API).
3. Implement content in detail
NOTE:I get the default term store directly, in default, SharePoint don ' t set it, so you have to set in Admin Center, or T He code would encounter issues.
Here are the example to retrieve the metadata navigation and print out.
JavaScript source Code<script>_spbodyonloadfunctionnames.push (' start '); function Start () {var scriptbase = _sp Pagecontextinfo.webserverrelativeurl + "/_layouts/15/"; $.getscript (Scriptbase + "SP. Runtime.js ", function () {$.getscript (scriptbase +" Sp.js ", function () {$.getscript (scriptbase +" Sp. Taxonomy.js ", function () {var termslist =" "; Context = SP. Clientcontext.get_current (); Gettermstores (); Console.log ("Success"); }); }); });} function Gettermstores () {this.session = SP. Taxonomy.TaxonomySession.getTaxonomySession (context); This.termstores = This.session.get_termStores (); This.groups = Session.getdefaultsitecollectiontermstore (). Get_groups (); Context.load (this.groups); Context.executequeryasync (Function.createdelegate (this, this.onquerysucceeded), function.createdelegate (This, this.onqueryfailed));} function onquerysucceeded (SENDEr, args) {var grouplist = "List: \ n"; var groupsenum = Groups.getenumerator (); while (Groupsenum.movenext ()) {var currentgroup = groupsenum.get_current (); var groupName = Currentgroup.get_name (); if (GroupName = = "Navigation") {this.termsets = Currentgroup.get_termsets (); Context.load (This.termsets, ' Include (Name, Id, CustomProperties) '); Context.executequeryasync (Function.createdelegate (this, this.ontermsetssucceeded), function.createdelegate (This, this.ontermsetsfailed)); Grouplist + = groupName + "\ n"; Console.log (Grouplist)}}}function onqueryfailed (sender, args) {//failure loading termstores . Console.log ("Failed to get Groups");} function ontermsetssucceeded (sender, args) {var termsetenum = This.termSets.getEnumerator (); var termsetlist = "Term sets: \ n" while (Termsetenum.movenext ()) {var currenttermset = termsetenum.get_current ( ); var termsetname = Currenttermset.get_name (); if (Termsetname = = "Navtop") {this.terms = Currenttermset.get_terms (); Context.load (This.terms, ' Include (Name, Id, CustomProperties, Localcustomproperties, Termscount) '); Context.executequeryasync (Function.createdelegate (this, this.ontermssucceeded), function.createdelegate (This, this.ontermsfailed)); }}}function ontermsetsfailed (sender, args) {alert ("Failed to get Termsets");} function ontermssucceeded (sender, args) {var termsenum = This.terms.getEnumerator (); while (Termsenum.movenext ()) {var currentterm = termsenum.get_current (); var termname = Currentterm.get_name (); var termid = currentterm.get_id (); Currentterm.get_objectdata (). Get_properties () ["CustomProperties"] ["test"] var propertied = currentterm.get_local CustomProperties (); var groupvalues = Propertied.group! = null? Propertied.group: ""; Console.log ("propertied:" + propertied._sys_nav_hovertext + "\ n" + propertied._sys_nav_simplelinkurl + "\ n" + groupvalue s); Console.log (Termname); Check If term have child terms if (Currentterm.get_termscount () > 0) {//term have sub terms. Recursiveterms (currentterm, 1); }}}function ontermsfailed (sender, args) {alert ("Failed to get Termsets");} function recursiveterms (Currentterm, NE Stedloop) {//loop count for formatting purpose. var loop = Nestedloop + 1; Get term child terms var terms = currentterm.get_terms (); Context.load (terms); Context.executequeryasync (function () {var termsenum = Terms.getenumerator (); while (Termsenum.movenext ()) {var newcurrentterm = termsenum.get_current (); var termname = Newcurrentterm.get_name (); Termid = newcurrentterm.get_id (); Tab out format. var loops= ""; for (var i = 0; I < loop; i++) {//Termslist + = "\ T"; Loops + = "\ T"; } console.log (loops + termname); Check If term had child terms. if (Currentterm.get_termscount () > 0) {//term has sub terms. Recursiveterms (newcurrentterm, loop); }}}, function () {alert ("fie"); Failure to load terms}); }</script>
The source link:https://cann0nf0dder.wordpress.com/2013/04/09/accessing-taxonomy-term-store-with-jsom/
Sharepoint Retrieve Taxonomy term Store via Javascript