Closed lifehackett closed 9 years ago
@lifehackett, currently there is not support for this on collections. There is a discussion on adding them to ampersand-collection going on here. As you can see it's a little tricky and still under discussion, but that might be the best place for this issue.
The way I've done the kind of filtering you mention is to add a filter to the subcollection with the query and then swap it out when the search text changes.
@mmacaula Thanks for pointing me towards that thread. I had a feeling it was probably more of an ampersand-collection
issue, but thought posting here I might get better insights on how to workaround the problem here. I really hope that it adds support for props/session
because at the moment that is a huge gap for me.
I didn't even think of your workaround! Although it feels a bit hacky, that is the best solution I have heard/come up with to solving this problem until ampersand-collection
adds support.
Thanks for the response.
Hi, I have a pretty common use case. I have a table displaying a list of people and and a text box that allows the user to filter the table by the person's name. I am using
ampersand-rest-collection
andampersand-model
for thepeople
andpersons
models respectively. On input to the text box I want to return an instance ofampersand-filtered-subcollection
.The problem I am running into is I don't see a way to add properties directly to the collection such that they properly get filtered. IE the "searchText" is a
session
property of the collection as opposed to an individual model, but I don't see support for this on collections. I tried adding a setter to the collection to imitate this behaviorThis mostly works, but the problem is the entire collection gets passed into my filter function and therefore returning true/false wouldn't work as opposed to the calling code iterating over the collection and passing in each individual model. The
_testModel
function only appears to work for individual models not collections.I feel like I must be missing something. How would you recommend setting this up?
Thanks