【问题标题】:valueHasMutated() - comptible with IE 8valueHasMutated() - 与 IE8 兼容
【发布时间】:2016-06-02 14:06:15
【问题描述】:

我有一个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>

【问题讨论】:

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


    【解决方案1】:

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

    您需要有一个触发标准模式的 Doctype (&lt;!doctype html&gt;)

    Article

    DocTypes

    【讨论】:

    • 很抱歉,但我必须这样做,因为在我的公司我看到统计数据,很多人还在使用 IE8,我同意你的看法
    • 是的,完全明白,我开发的很多公司都要求与 ie 兼容。它确实无缘无故地制造了很多问题。见上面的编辑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 2012-09-25
    相关资源
    最近更新 更多