Answer the question
In order to leave comments, you need to log in
How to get related object or chain in emberjs?
Hello. I study Amber. Stumbled upon a strange thing, how can I get the associated object?
And another question, how to edit links between objects...
App.Object = DS.Model.extend({
children: DS.hasMany('object', {async: true, inverse: 'parent'}),
parent: DS.belongsTo('object', {async: true, inverse: 'children'}),
});
App.ChildNodeComponent = Ember.Component.extend({
drop: function(event) {
var target = this.get('node'); // объект в который переместили
var obj = App.DragerObj;
// как узнать, не является ли target, дочерним объектом obj?
},
dragStart(event) {
App.DragerObj = this.get('node'); // сохраняем перемещаемый объект
},
});
Answer the question
In order to leave comments, you need to log in
It turned out to manipulate the connections, everything seems to be automatically affixed.
App.Object = DS.Model.extend({
children: DS.hasMany('object', {async: true, inverse: 'parent'}),
parent: DS.belongsTo('object', {async: true, inverse: 'children'}),
find_parents: function(elem){
var in_parent = false;
parent = this.get('parent').content
in_parent = parent === elem;
if(!in_parent && parent.get('parent').content){
in_parent = parent.find_parents(elem);
}
return in_parent;
},
});
var move_node = function(options){
var target = options.target;
var element = options.element;
// не является собой, не является потомком себя
if(element != target && !target.find_parents(element)){
var children = target.get('children');
children.pushObject(element);
///////////////////////////////////////////////////////
ИЛИ
element.set('parent', target);
element.save();
}
};
App.ChildNodeComponent = Ember.Component.extend({
attributeBindings : [ 'draggable' ],
draggable : true,
drop: function(event) {
opt = {
'target':this.get('node'),
'element':App.DragerObj,
}
move_node(opt);
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question