Closed cksachdev closed 4 years ago
_.map(Adapt.contentObjects._byAdaptID, (co, key) => console.log(co[0].attributes.displayTitle) );
Title should print in a sequence
This arguably shouldn't be the case. The private _byAdaptID
property just groups models by their ID. It cannot be replied upon to get an indication of the course structure, either with automatically-generated IDs from the authoring tool or with hand-typed IDs in JSON.
If you told us a bit about the problem you're trying to solve we could advise further with a solution.
For example, to print a sorted list of content object titles in a framework 5.2 course, you could utilise the following code:
Adapt.course.getAllDescendantModels(true).forEach(function(model) {
var type = model.get('_type');
if (type === 'menu' || type === 'page') {
console.log(model.get('displayTitle'));
}
});
This gets easier in an upgraded framework (version 5.5 or later):
Adapt.course.getAllDescendantModels(true).forEach(model => model.isTypeGroup('contentobject') && console.log(model.get('displayTitle')));
@tomgreenfield I have created a footer navigation component, which should allow the user to navigate to "Next", "Back" and "Go back to main menu". In order to achieve this, I needed the sequence of data in the order I am expecting.
Parent1
Parent1 - Page1
Parent2
Parent2 - Page1
Parent2 - Page2
I will try out the getAllDescendantModels method and let you know if it gives me the right sequence.
Update: Tried out the method in console and getting the sequence as expected.
Expected Behaviour
Export scenario:
Pre-condition: Create a course with 2 menu items, like below:
Each page having just one text component.
Steps:
Adapt.contentObjects._byAdaptID
_.map(Adapt.contentObjects._byAdaptID, (co, key) => console.log(co[0].attributes.displayTitle) );
Title should print in a sequence like below:Actual Behaviour
Sequence of contentObjects isn't proper, printing displayTitle for _byAdaptID prints like
Same is reproducible when trying to import a course which contains menu and page in contentObjects.
Versions