onyx.Menu
. The idea is to pass controls to the menu, and create components from them. Currently, if I add a new item, it gets appended at the end of the list. However, I want to keep the menu items sorted in a particular order.enyo.kind({I tried this with a plain component first, and sorting the children array during the flow worked perfectly. But, the
name: "myMenu"
kind: "onyx.Menu",
addMenuItem: function(menuItem) {
var controls;
menuItem.kind = menuItem.kind || this.defaultKind;
controls = this.controls;
if (!_.find(controls, function(control) {
return control.name === menuItem.name;
})) {
menuItem = this.createComponent(menuItem);
}
},
menuItemComparator: function(a, b) {
/* some sorting stuff... */
},
flow: enyo.inherit(function(sup) {
return function() {
this.children.sort(this.menuItemComparator);
sup.apply(this, arguments);
};
})
});
onyx.Menu
has a nested scroller, so the children
array only contains the scroller, not the menu items. I could retrieve the inserted menu-items in the following way:
var children = this.getScroller().getStrategy().$.client.children;But that seems rather dirty.. I figure, the
onyx.Menu
knows to put the newly created menuItem all the way in the scroller strategy's client, so there must be some way to discover where newly-created components go... However, I cannot find out how... Any ideas? It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
1) This will sort the entire list every time a single item gets added. If I could find out which component will become the parent, I could load the existing list of children and figure out the correct index at which to insert the new item.
2) The new menuItem renders at the end of the list, rather than at the correct sort order. I don't know how to fix this either.