valueHasMutated() - 与 IE 8 兼容

valueHasMutated() - comptible with IE 8

我有一个 observable array,我在其中填充

之类的对象
{
    thisId: value.id,
    nom: value.nom,
    isChecked:check
};

代码填写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);
        }
    });
};

当我尝试使用 IE 8 时,我遇到了这个错误

Unable to parse bindings

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

Message : Identifier, string or number expected

发现错误的视图部分

<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>

IE8 不支持兼容模式下的属性选择器。

您需要具有触发标准模式的 Doctype (<!doctype html>)

Article

DocTypes