i have a term set of details which have students as one term where i have three terms computer, biology, commerce.Inside to each term i have data which are terms.
details
students
computer
john
jane
biology
larry
jevin
commerce
sam
derik
what i need is i need an array as result
output:
var output = [
{id:"qweqdsadas", name:"john", dept:"computer"},
{id:"eqweqwer", name:"jane", dept:"computer"},
{id:"qweqweqwe", name:"larry", dept:"biology"},
{id:"cxasdasd", name:"jevin, dept:"biology"},
{id:"treeyrth", name:"sam", dept:"commerce"},
{id:"jkhkjhkhk", name:"derik", dept:"commerce"}
]
i am able to create the array see the below code
const fetchDetails = () => {
let context = initializeContextData[0];
context.load(studentTerms[0]) // which holds all the terms from students
// term
context.executeQueryAsync(() => {
for(let i=0;i<studentTerms[0].get_count();i++){
let child = studentTerms[0].getItemAtIndex(i)
let subChild= child.get_terms();
context.load(subChild);
context.executeQueryAsync(() => {
for(let i=0;i<subChild.get_count();i++){
let studentDetails = subChild.getItemAtIndex(i)
output.push({
id: studentDetails.get_id()._m_guidString$p$0,
name: studentDetails.get_name(),
dept: child.get_name()
})
}
})
}
})
}
// success method
const success = () => alert("data successfully pushed into array")
after creating the array i need to call a success method , since i am running in for loop and executeQueryAsync is an asynchronus function, how can i call a success method once the entire data is pushed into array, i tried $.Deferred but it doesn't seem to properly work . i am a beginner to javascript.
thanks in advance !!