meteor - How do I modify the item of an array passed as data context in a child template? -
i have local collection stores arrays of odds:
checkscollection = new mongo.collection(null); checkscollection.insert({ odds: ['', ''], oddsaverages: ['', ''], oddscompeting: ['', ''] });
and helper sets parent data context:
template.step1.helpers({ bet: () => checkscollection.findone() });
and need child template can modify index of array checkscollection. @ moment call that:
{{>inputodds odds=bet.odds.[0] label='the odds being offered you:' placeholder='any odds style works! equivalent examples: 1/4 1.25 -400'}} {{>inputodds odds=bet.odds.[1] label='the odds offered opposite outcome:' placeholder=''}}
later might call {{#each ... in ...}} loop through oddsaverages example. child template:
<template name="inputodds"> <div class="form-group"> <label for="odds">{{label}}</label> <input type="text" class="form-control" id="odds" value="{{odds}}" placeholder="{{placeholder}}"> </div> </template>
putting more simply, question modify , write after lines below in order allow child template update data context (therefore call update , modify values arrays of checkscollection):
template.inputodds.events({ 'keyup input.form-control': function (event, template) {
i have solved yey! if in same situation, use following code:
var objectforset = {}; objectforset[key + '.' + index] = value; //todo remove debugging code below. line creates rendering problem is: checkscollection.update({}, {$set: objectforset}); console.log(`modifying local collection @ key: ${key}; array index: ${index};`); checkscollection.update({}, {$set: objectforset});
Comments
Post a Comment