Open stalniy opened 8 years ago
Also I created an issue in rivets repository. Fix of that will allow to iterate over backbone collections (and not only) https://github.com/mikeric/rivets/issues/583
Or you could add something like this:
let eachBinderRoutine = rivets.binders['each-*'].routine;
rivets.binders['each-*'].routine = function(el, collection) {
if (collection.models) {
collection = collection.models;
}
return eachBinderRoutine.call(this, el, collection);
};
The linked issue (mikeric/rivets#583) and linked issue there proposes some alternative ways to solve this problem. Still i don't really like those solutions :(
When adapter returns Collection.models
, i loose access to attributes (builtin or custom) defined at my Collection
.
So I did this,
// rivets cant iterate over Backbone.Collection -> return Array
if (value instanceof Collection) {
value.models.parent = value;
return value.models;
}
This way i can check for it. obj.parent instanceof Backbone.Collection
And access attrs using obj.parent.attr
.
I know in order to iterate over backbone collection adapter returns internal array instead of collection. That really annoying for cases when you need collection, for example when you pass it as parameter to component (as attribute)
So, I suggest to move such decision to configuration option:
cc: @azproduction @der-On @generalov @StephanHoyer @Jmeyering @jeron-diovis