I have a collection called Rulesets - each ruleset has an array of "rules". I have the following html which displays each ruleset and each rule:
<template name="rulesets">
{{#each rulesets}}
{{>rulesetSingle}}
{{/each}}
</template>
<template name="rulesetSingle">
{{#each rules}}
<p class="rule-description">{{this}}
<a href="#" class="rule-delete-btn">x</a>
</p>
{{/each}}
</template>
I want to be able to remove the rule when the user clicks the "rule-delete-btn".
I have the following javascript to do this:
Template.rulesetSingle.event({
'click .rule-delete-btn': function(e){
e.preventDefault();
var array = Rulesets.rules;
var index = array.indexOf(this);
array.splice(index, 1);
}
});
The delete isn't working because the "array" declaration isn't pulling a valid array. How can I find and store the array that contains "this" which is the current rule that needs to be deleted?