I am trying to populate the content of a textarea by extracting data from a nested array. In my helper function, I have specified the document id and the element id. The goal is to extract the content of the text
field from the findOne result and display it in the template. However, I am facing difficulty in retrieving the correct field from the findOne result using the spacebar helper {{infotext}}
:
Sample Document JSON
{
"_id" : "8rmzAN3yw79TAKNeD",
"title" : "title",
"tooltips" : [
{
"element" : "16091688",
"text" : "Lorem"
},
{
"element" : "944a0d46",
"text" : "ipsum"
}
]
}
Helper Function
Template.infotext.helpers({
infotext: function() {
var id = '8rmzAN3yw79TAKNeD',
elementId = Session.get('elementID');
return Articles.findOne({_id: id, 'tooltips.element': elementId});
}
});
Template Code
<template name="infotext">
<form>
<textarea>{{infotext}}</textarea>
<input type="submit" class="btn btn-default" value="save">
</form>
</template>