简体   繁体   English

IE8中的KnockoutJS伪绑定失败

[英]KnockoutJS pseudobinding failing in IE8

The following fails in IE8, but works in real browsers 在IE8中以下操作失败,但在实际的浏览器中有效

<div data-bind="with: currentItem, visible: currentItemState() === 'view'">

    <!-- ko if: resource().versions().length -->
    <!-- ko with: resource().versions()[0] -->

    <div style="margin-top: 15px;" data-bind="visible: error()">
         .....

    <!-- /ko -->
    <!-- /ko -->

Basically I'm getting property 'error' is null or undefined which means the with (and if ) bindings aren't working properly. 基本上,我得到的property 'error' is null or undefined ,这意味着with (以及if )绑定不能正常工作。 This is probably because IE8 is stripping the comments out, which I've seen it do in other contexts, like within a <select> node, but I've never seen it do that in a place like this. 这可能是因为IE8正在删除注释,我已经看到它在其他上下文中(例如在<select>节点中),但是我从未见过它在这样的地方这样做。

Is there a good way to fix this (without working around the problem by changing my html structure)? 是否有解决此问题的好方法(无需通过更改HTML结构来解决此问题)?

Most of the time when I have come across this, it is not down to knockout but HTML. 在大多数情况下,我遇到的不是淘汰赛,而是HTML。 Things like not closing tags off properly such as having a self closing <label /> that busted it. 诸如无法正确关闭标签之类的事情,例如具有导致<label />自动关闭的<label />

IE8 is very particular about this stuff. IE8对这个东西非常讲究。 I had one place where it didn't render the bottom half of a <!-- ko if --> because of the lable issue 由于存在问题,我在一个地方没有呈现<!-- ko if --> if- <!-- ko if -->的下半部分

Wrap the second containerless binding within an empty div so that it is parsed correctly in all browsers 在空div中包装第二个无容器绑定,以便在所有浏览器中正确解析

<div data-bind="with: currentItem, visible: currentItemState() === 'view'">
    <!-- ko if: resource().versions().length -->
        <div>
        <!-- ko with: resource().versions()[0] -->
            <div style="margin-top: 15px;" data-bind="visible: error()">
        <!-- /ko -->
        </div>
    <!-- /ko -->
</div>

I'm not sure if there's a proper way to fix this, but it turns out knockout's with binding is intelligent enough to not render the nodes at all if the with*ed* value is undefined. 我不确定是否有适当的方法来解决此问题,但是事实证明,如果with * ed *值未定义,则with绑定的敲除很聪明,根本不会渲染节点。 So replacing both of those pseudo bindings with just 因此,将两个伪绑定替换为

<div data-bind="with: resource().versions()[0]">

appears to fix the problem. 似乎可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM