Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I am working on a Meteorjs application where I have a syllabus and I want to copy or clone this syllabus. Here in my syllabus there are modules which can till multiple levels means a mudule can have another module as its child module and so on.for example i have a module Grammer and grammer has another module named tenses and tenses ahs some other module named present past and future these will seems like this.
tenses past simple negative interogative present simple negative interogative future simple negative interogative
databse fields are name, parent_id, has_children, syllabus_id these mudules can further have some sub modules or children. In database to check if a module have further children i have a field boolean has_children and parent_id to relate the child with the parent.If element is a root element its 'parent_id` will be null.
has_children
parent_id
for this i tried to reach every element recursively but i am able to reach only one element at one level. means i am not reaching to the siblings of an element but the children.
My code is :
cloneSyllabus:function(syllabi_id){ syll_obj=Meteor.syllabi.findOne({_id:syllabi_id}); new_syllabi_id=Meteor.syllabi.insert({ subject_id:syll_obj.subject_id, level_id:syll_obj.level_id, }); var parent_objs = Meteor.collecton.find({ parent_id:null, syllabus_id:syllabi_id}).fetch() for(var i=0;i<syll_design_objs.length;i++){ makeClone(parent[i],null,new_syllabi_id) } }
and the other function which is creating the objects recursively is
function makeClone(item,parent_id,syllabi_id){ var item_id=item._id delete item._id item.parent_id=parent_id item.syllabus_id=syllabi_id var new_parent_id=Meteor.syllabi_design.insert(item) if(item.has_children){ child_items=Meteor.collection.find({parent_id:item_id}).fetch(); for(i=0;i<child_items.length;i++){ makeClone(child_items[i],item_id,syllabi_id); } } }
But using this i am able to retrieve only one element at the same level but not its siblings. i will be able to create tenses past simple negative interogative tell me guys where i am making a mistake while retrieving these objects.Or tell me any otherway to accomplish the task. Here i have to change only the syllabus_id and create all the objects again.
Everything is perfect in your code just add recursive function termination statement in your code. cloneSyllabus:function(syllabi_id){ syll_obj=Meteor.syllabi.findOne({_id:syllabi_id}); new_syllabi_id=Meteor.syllabi.insert({
subject_id:syll_obj.subject_id, level_id:syll_obj.level_id, }); var parent_objs = Meteor.collecton.find({ parent_id:null, syllabus_id:syllabi_id}).fetch() for(var i=0;i<syll_design_objs.length;i++){ makeClone(parent[i],null,new_syllabi_id) } return }
And declare the variable i as var i and child_objs as var child_objs in loop of the function makeClone because these variable are being treated here as a glabal variable in your code.
i
var i
child_objs
var child_objs
makeClone
function makeClone(item,parent_id,syllabi_id){ var item_id=item._id delete item._id item.parent_id=parent_id item.syllabus_id=syllabi_id var new_parent_id=Meteor.syllabi_design.insert(item) if(item.has_children){ child_items=Meteor.collection.find({parent_id:item_id}).fetch(); for(var j=0;j<child_items.length;j++){ makeClone(child_items[i],item_id,syllabi_id); } } else{ return } }
Hope this will work perfect for you
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.