I know there are multiple questions about this and I have solved the first problem through those answeres. I decided to not polute my global namespace and use this type of solution. But now I have a different problem relating the same frameworks.
My models start like this.
define([
'backbone',
'backbone.relational'
], function(Backbone){
var MenuNode = function () {
Backbone.RelationalModel.apply(this,arguments);
}
var NodeCollection = function() {
Backbone.Collection.apply(this,arguments);
}
MenuNode = Backbone.RelationalModel.extend({
constructor: MenuNode,
relations:[
{
type: Backbone.HasMany,
key: "children",
relatedModel: MenuNode,
collectionType: NodeCollection,
reverseRelation: {
key: "parent"
}
}
]
})
NodeCollection = Backbone.Collection.extend({
constructor: NodeCollection,
model: MenuNode,
url: function() {
return "/nodes"
}
})
This will create the models nessecary for my application, which is a jstree.
But my question is how I create the connection with the api and my relations, and how I get the current children of a node using backbone.
I have the api:
nodes/ returns the root nodes in a simplified version
nodes/id returns the full info about node, with children and parent simplified
nodes/id/children returns the simplified version of the children of a specific node
But how can I get the current children of a specific node through backbone?
I want to be able to make a call when i want to load the children, but not preload the children. Im trying to save the server for requests. Because have a big tree view, means that its unessecary to load the whole tree.
Just ask any questions to clarify anything more.
Thx ahead