valueHasMutated() - 与IE 8兼容

时间:2016-06-02 14:06:15

标签: javascript knockout.js ie8-compatibility-mode

我有一个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时,我有这个错误

  

无法解析绑定

     

绑定值:attr:{for:' thisObservableArray - ' + $ data.thisId}

     

消息:预期的标识符,字符串或数字

发现错误的视图部分

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

1 个答案:

答案 0 :(得分:0)

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

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

Article

DocTypes

enter image description here