yepzy yepzy - 5 months ago 27
Javascript Question

valueHasMutated() - comptible with IE 8

I have an

observable array
where I fill with objects like

{
thisId: value.id,
nom: value.nom,
isChecked:check
};


the code to fill the
observableArray


self.fullFilter = function() {
var check;
self.thisObservableArray.removeAll();
self.anOther1.removeAll();
self.anOther2.removeAll();
$.get("data/"+self.currentOngletId()+"?ajax=1", function(data) {
$.each(data, function(i, item) {
$.each(item, function(j, value) {
check = null;
switch (i) {
case 0:
try{
if(value.observable_value.length > 0){
check = "checked";
}
var elem = {
thisId: value.id,
nom: value.nom,
isChecked:check
};
self.thisObservableArray().push(elem);
} catch(e){
console.warn('fullfilter -> observable_value '+e)
}
break;
case 1:
//an other same code different variables
break;
case 2:
//an other same code different variables
break;
}
});
});
try {
self.thisObservableArray.valueHasMutated();
self.anOther1.valueHasMutated();
self.anOther2.valueHasMutated();
} catch(e){
self.error("fullfilter",e);
}
});
};


When I try with IE 8, I have this error


Unable to parse bindings

Bindings value: attr:{for:'thisObservableArray-'+$data.thisId}

Message : Identifier, string or number expected


the part of the view where the error is found

<fieldset>
<legend>Statut</legend>
<ul data-bind="foreach: thisObservableArray()">
<li>
<div class="form-group">
<label data-bind="attr:{for:'thisObservableArray-'+$data.thisId}">
<input class="observable-input" data-bind="attr:{id:'thisObservableArray-'+$data.thisId, name:'thisObservableArray['+$data.id+']', checked: $data.isChecked}" type="checkbox"/>
<span data-bind="text: $data.nom"></span>
</label>
</div>
</li>
/ul>
</fieldset>

Answer

IE8 does not support attribute selectors in Compatibility Mode.

You will need to have a Doctype (<!doctype html>) that triggers Standards Mode.

Article

DocTypes

enter image description here

Comments