Apologies for another question on JSViews. I really love this system, but I am struggling occasionally.
I have a simple template which only needs to update which items in the array to show on select box change:
However, when I change the data "isSelected" the template is not being updated with the following:
ie:
function someClickFunction(sel) {
value = sel.value;
....
la_configure_list[0].isSelected = false;
$.observable(la_configure_list).refresh(
la_configure_list.slice(0)
);
}
if I change it to
$.observable(la_configure_list).refresh(
JSON.parse(JSON.stringify(la_configure_list))
);
it updates just fine.
Can anyone tell me what I am doing wrong:
<script id="la-config-overview-list-template" type="text/x-jsrender">
{^{if isSelected}}
<div class="col s12 la_review_list_item" data-index="{{:#index}}">
<div class="card">
<div class="card-content" style="padding: 10px;">
<div class="col s12 m6 l5 xl5">
<h6 style="font-weight: 700;" class="">{{:title}}</h6>
<div>Categories:</div>
<div>
{{for categories}}
<span class="chip">{{:#data}}</span>
{{/for}}
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
{{/if}}
my html is
<div id="teacher_la_review_overview_main_wrapper" class="container body-content">
<div class="row" style="margin-bottom: 0;"></div>
</div>
the array is:
la_configure_list = [
{
isSelected:true,
title: "Title",
categories: ["1", "2"....]
},
....
]
I set up the template:
$.templates("#la-config-overview-list-template").link("#la_review_list_overview_list_wrapper .row", la_configure_list);
I tried using $.view(elem).refresh(), but as my click action to update isSelected is outside the template, I cannot find the correct "elem" to use.
EDIT - Added actual update code:
function CategoryUpdate(sel) {
var catSelected = sel.value;
var catText = sel.options[sel.selectedIndex].text;
if (catSelected !== "-1") {
for (var cs = 0; cs < la_configure_list.length; cs++) {
if (la_configure_list[cs].categories == null) {
la_configure_list[cs].isSelected = false;
continue;
}
var categories = la_configure_list[cs].categories;
var isFound = false;
for (var c = 0; c < categories.length; c++) {
var category = categories[c];
if (category === catText) {
la_configure_list[cs].isSelected = true;
isFound = true;
}
}
if (!isFound) {
la_configure_list[cs].isSelected = false;
}
}
} else {
for (var x = 0; x < la_configure_list.length; x++) {
la_configure_list[x].isSelected = true;
}
}
$.observable(la_configure_list).refresh(
JSON.parse(JSON.stringify(la_configure_list))
);
}