SPFx - List out all labels within a Term Set (Term store)
-
08-02-2021 - |
Question
Inside a SPFx web part, I have been trying really hard to list out the labels (red, blue, green) within the Favourite term set. I have not yet been able to achieve this.
Does anybody know how to do this? My brain is melting :(
code:
public async componentDidMount() {
const store: ITermStore = taxonomy.termStores.getByName("Taxonomy_O1cHqzMmDZNz4UeaKJLVpA==");
// get a single term by id
const term: ITerm = store.getTermById("6a488843-cebc-47b7-8606-e4e165e6fceb");
const labels: ILabels = term.labels;
const labelsWithData = term.labels.get();
{ setTimeout(() => {
console.log('1', store);
console.log('2',labels);
console.log('3',labelsWithData);
}, 2000); }
}
Solution
Sample test code for your reference.
public componentDidMount() {
var store: ITermStore = taxonomy.termStores.getByName("Taxonomy_hAIlyuIrZSNizRU+uUbanA==");
var set: ITermSet = store.getTermSetById("70719569-ae34-4f24-81b9-0629d68c05aa");
// load the data into the terms instances
set.terms.get().then((terms:ITerm[])=>{
terms.forEach((term: ITerm) => {
console.log(term['Name']);
})
});
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange