I have a modal sheet dynamically created and the template has handlebars inside, when the modal is opened I feed the content with the data.
The issue I am having this content data inside this modal sheet can be updated.
I am using self.$setState method to change and update the component data of the array previously passed.
With a new page there is no problem using self.$setState for this but inside a modal sheet nothing happens to update the component data using self.$setState.
any solution or ideas how to make this work?
here the code
var tmpl = '<div class="sheet-modal" style="height:100%;">\
<div class="sheet-modal-inner">\
<div class="page-content infinite-scroll-content">\
{{#ifCond weatherMetric "==" "celsius"}}
{{converttocelsius weather.current.temp}}
{{else}}
{{converttofarenheit weather.current.temp}}
{{/ifCond}}
<label class="toggle color-black">\
<input type="checkbox" checked>\
<span class="toggle-icon"></span>\
</label>\
</div>\
</div>\
</div>';
var obj = app.utils.extend(weather, {
weatherMetric: 'celsius',
});
var dynamicSheet = app.sheet.create({
content: Template7.compile(tmpl)(obj),
on: {
open: function (sheet) {
console.log('Sheet open');
},
opened: function (sheet) {
console.log('Sheet opened');
var toggle = app.toggle.create({
el: '.toggle',
on: {
change: function () {
var toggle = app.toggle.get('.toggle');
if (toggle.checked) {
console.log('Toggle checked');
self.$setState({
weatherMetric: "celsius"
});
} else {
console.log('Toggle unchecked');
self.$setState({
weatherMetric: "farenheit"
});
}
}
},
}
});
Let us say inside the modal sheet there is the weather information of a city for instance the temperature and this can be changed from celsius the default value to fahrenheit with a toggle.
The problem it seems that because the template was already rendered when opened the modal sheet, the component data cannot be updated after using self.$setState.
Is there any ideas to update component data with self.$setState in a dynamically created modal sheet?
thanks for the ideas!