IE8 knockout error - Unable to process binding

雨燕双飞 提交于 2019-12-13 04:13:00

问题


I have a viewmodel like this,

var sectorViewModel = function() {
    this.currentValue = ko.observable();
    this.previousValue = ko.observable();
    ....
    this.maxValue = ko.computed(function() {
        return Math.max(this.currentValue(), this.previousValue(), ...);
    }, this);
}

ko.applyBinding(sectorVM, document.getElementById("divSector");

And this is the html snippet where I am doing the data-bind,

<div id="divSector">
    ...
    <div class="bar" data-bind="style: {width: (currentValue()*100)/maxValue() + '%'}"></div>
    ...
</div>

Works fine in all browsers except for IE8. In IE8 I see this error in dev tool -

Invalid argument. Unable to process binding "style: function() {return..."

Any idea how can I get this to work in IE8?

Thanks.


回答1:


Investigate the exact result that gets returned from your computed.

According to the following:

https://github.com/knockout/knockout/issues/525

The newer browsers probably handle a result such as xx.asmanydecimalplacesrequired% but may not be compatible with IE8. You should make sure the returned value is a compatible width style property for IE8 - e.g. trim it to 2 decimal places - that's the first thing I would try.

Let me know if this helps, because I'm totally figuring this out via research, and don't forget to vote up if that's the case ;P



来源:https://stackoverflow.com/questions/31037759/ie8-knockout-error-unable-to-process-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!