简体   繁体   English

聚合物组件中的剔除与阴影Dom绑定正确,但与阴影Dom绑定

[英]Knockout in Polymer Component binds correctly with shady Dom but not shadow Dom

I've the following polymer component (only for testing): 我有以下聚合物成分(仅用于测试):

<dom-module id="visu-conveyor">
    <template>
        <div id='conveyor'>
            {{objectName}}
            <div style="width: 80px; height: 90%;">
                <div style="width: 10px; height: 10px; background: blue;" data-bind="visible: B.B.Value"></div>
                <span data-bind="text: $data"></span>
            </div>
        </div>

    </template>

    <script>
    Polymer({
        is: "visu-conveyor",
        properties: {
            objectName: String
        },
        attached: function () {
            var self = this;
            var dc = ko.dataFor(self);
            ko.applyBindings(dc, self.$.conveyor);
        }
    });
    </script>
</dom-module>

this component maybe hosted in another component like this: 该组件可能托管在另一个这样的组件中:

<dom-module id="visu-tag-root-canvas">
    <template>
        <div style="height: 100%; width: 100%" id="rootObj">
            <content></content>
        </div>

    </template>

    <script>
    Polymer({
        is: "visu-tag-root-canvas",
        properties: {
            tagRoot : String
        },
        ready: function () {
            var self = this;

            var dc = ko.dataFor(self);

            if (self.tagRoot != null) {
                //self.$.rootObj.setAttribute("data-bind", "with: " + self.tagRoot);
                //todo -> get folder recursive
                ko.applyBindings(dc[self.tagRoot], self.$.rootObj);
            } else {
                ko.applyBindings(dc, self.$.rootObj);
            }
        }
    });
    </script>
</dom-module>

For Example a Page may look like this: 例如,页面可能看起来像这样:

<visu-tag-root-canvas>
    <visu-conveyor style="width: 88px; height: 130px; top: 74px; position: absolute; left: 64px;" object-name="HH66"></visu-conveyor>
    <visu-conveyor style="width: 88px; height: 130px; top: 74px; position: absolute; left: 160px;" object-name="aa31"></visu-conveyor>
    <visu-tag-root-canvas tag-root="A" style="left: 284px; position: absolute; top: 255px; width: 305px; height: 216px;">
            <visu-conveyor style="width: 88px; height: 130px; top: 27px; position: absolute; left: 30px;" object-name="EE77"></visu-conveyor>
            <visu-conveyor style="width: 88px; height: 130px; top: 27px; position: absolute; left: 126px;" object-name="II88"></visu-conveyor>
    </visu-tag-root-canvas>
</visu-tag-root-canvas>

That means the 2 visu-conveyors inside the 2nd visu-tag-root-canvas should bind to "ABB" and the ones outside to "BB"! 这意味着第二个visu-tag-root-canvas内的2个visu传送带应绑定到“ ABB”,而外部的绑定到“ BB”!

This works with shady dom! 这适用于阴暗的dom! But when I enable shadow Dom, all bind to the same Variable! 但是,当我启用影子Dom时,所有绑定到同一变量! "BB" “ BB”

As Addition my DataContext for Binding looks like this: 另外,用于绑定的DataContext如下所示:

{
A {
  B {
    B {
      Value 
      }
    }
  }
B {
  B {
    Value
    }
  }
}

Was my fault. 是我的错 Since ShadowDom bring real encapsulation, ko.dataFor(self) returns the same for all visu-conveyor, because the dom is encapsualted! 由于ShadowDom带来了真正的封装,因此ko.dataFor(self)对所有visu-conveyor都返回相同的内容,因为dom已封装!

If I change "self.$.rootObj" to "self" it works with shadow dom enabled 如果我将“ self。$。rootObj”更改为“ self”,则启用了影子dom

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

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