These are chat archives for canjs/canjs

17th
Nov 2016
Viktor Busko
@Lighttree
Nov 17 2016 18:09
(function() {
    var participantsListViewModel = can.Map.extend({
        define: {
            participants: {
                Value: SelfService.participants.model.List,
                get: function(currentValue) {
                    currentValue.replace(SelfService.participants.model.findAll());
                    return currentValue;
                }
            }
        },

        filter: function (term) {
            var filteredList = this.attr('participants').filter(function(item) {
                return item.firstName.toLowerCase().startsWith(term);
            });

            this.attr('participants', filteredList);
        }
    });

    can.Component.extend({
        tag: 'participants-list',
        template: can.view('#participantsList-template'),
        viewModel: participantsListViewModel
    });
}());
Guys, I have such component that represents list of users, and I would like to add simple filter for this list.
I'm a bit stucked with filter, when I try to set new value for participants it calls getter and rewrites filter results by results from findAll().
How to avoid this ?
Chasen Le Hara
@chasenlehara
Nov 17 2016 18:12
Where is term coming from? I would make term a property in the view model, then have another filteredParticipants property that has a getter with the same filtering logic.
Does that make sense?
Viktor Busko
@Lighttree
Nov 17 2016 18:13
<input type="text" placeholder="Search participants..." can-keyup="{filter @element.val}"/>
let me think :)
then have another filteredParticipants property that has a getter with the same filtering logic.
So in case when I don't use filter this is just copy of original participants ? and in my view I had to use this copy as well
Chasen Le Hara
@chasenlehara
Nov 17 2016 18:15
Right, if there isn’t a term, you would just return participants (doesn’t have to be a copy).
Kevin Phillips
@phillipskevin
Nov 17 2016 20:54
@roemhildtg It looks like {name}="object[key]” is working ok. I explained what was going on with that JSBin in the issue. Let me know if you have any questions.
Chasen Le Hara
@chasenlehara
Nov 17 2016 22:56
Just tweeted about a training in Chicago on Saturday: https://twitter.com/canjs/status/799381240868503552
Retweets appreciated!