here is a tree example I got from the Web (sorry, unable to trace that link), which I have put up in Plunkr: http://ift.tt/1NUsHUq
Here is the snippet which is the code to control the checkboxes in the tree:
App.TreeNodeController = Ember.ObjectController.extend({
isExpanded: false,
checked: false,
contentDidChange: function() {
this.set('checked', App.get('selectedNodes').contains(this.get('content')));
}.observes('content'),
toggle: function() {
this.set('isExpanded', !this.get('isExpanded'));
},
addChild: function() {
var text = window.prompt('Enter text for node:');
var node = {
text: text,
children: []
};
this.get('children').pushObject(node);
},
checkedDidChange: function() {
var selectedNodes = App.get('selectedNodes'),
node = this.get('content');
if (this.get('checked')) {
if (!selectedNodes.contains(node)) {
selectedNodes.pushObject(node);
}
this.get('content').children.forEach(function(controller) {
selectedNodes.pushObject(controller);
});
} else {
selectedNodes.removeObject(node);
this.get('content').children.forEach(function(controller) {
selectedNodes.removeObject(controller);
});
}
}.observes('checked')
});
The issue here is : Suppose, I expand a parent node, and then select the parent node checkbox, the children's checkboxes don't get selected.
Can someone please help?
Aucun commentaire:
Enregistrer un commentaire