javascript - Using helpers inside a keypath with ractivejs -


i have function called on click of element , comparing 2 arrays. first array printed out dom expression filters array.

handlebars:

{{#each search(~/budgets, searchvalue, 'accountname'):i}}     <p on-click="comparevalues">{{accountname}}</p> {{/each}} 

js:

ractive.on('comparevalues', function(target) {     if(ractive.get(target.keypath + '.accountname') === ractive.get(target.keypath.replace('budgets', 'accounts') + '.accountname') {         console.log(true);     } else {         console.log(false);     } }); 

an example target.keypath "${search(budgets,searchvalue,"accountname")}.4".

i able compare resulted array array go through expression tried use replace switch arrays being used in expression.

is possible use expression on array has gone through expression , has result getting undefined when changing array?

you may able use event context grab current item in array:

ractive.on('comparevalues', function() {     var current = this.event.context,         index = this.event.index.i; }); 

otherwise, can define computed property search:

var r = new ractive({     el: document.body,     template: '#template',     computed: {         search: function(){             var budgets = this.get('budgets'),                 searchvalue = this.get('searchvalue'),                 searchfield = this.get('searchfield')              return budgets.filter(function(each){                 return each[searchfield] = searchvalue;             });         }     } }); 

then can use in template:

{{#each search:i}}     <p on-click="comparevalues">{{accountname}}</p> {{/each}} 

and via api:

ractive.get('search.' + index + '.accountname') 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -