0

I am using react to get the term by id, but the problems is that I am not able to get any child term under the term.For example:

-IT

--software

--hardware

IT is term not termSet.

taxonomy.getDefaultSiteCollectionTermStore() .getTermById(this.props.top) .get().then( Alltop=>{ console.log(Alltop) this.setState({terms:Alltop}) } );

for termSet I am able to get all terms using taxonomy.getDefaultSiteCollectionTermStore() .getTermSetById(this.props.terSetId).terms .get()

2

Use PNP SP taxonomy in your SPFX code as below,it easy to use and supported with SPFx

import {
    taxonomy,
    ITermStore,
    ITerms,
    ILabelMatchInfo,
    ITerm,
    ITermData
} from "@pnp/sp-taxonomy";

const store: ITermStore = await taxonomy.termStores.getByName("Taxonomy_v5o/SbcTE2cegwO2dtAN9l==");

// get a single term by id
const term: ITerm = store.getTermById("0ba6845c-1468-4ec5-a5a8-718f1fb05431");

// get single get merged with data
const term2: ITerm = store.getTermById("0ba6845c-1468-4ec5-a5a8-718f1fb05431").get();

// use select to choose which fields to return
const term3: ITerm = store.getTermById("0ba6845c-1468-4ec5-a5a8-718f1fb05431").select("Name").get();

// get a term from a term set
const term4: ITerm = store.getTermSetById("0ba6845c-1468-4ec5-a5a8-718f1fb05431").getTermById("0ba6845c-1468-4ec5-a5a8-718f1fb05431");

Ref - https://pnp.github.io/pnpjs/sp-taxonomy/docs/terms/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.