代码之家  ›  专栏  ›  技术社区  ›  Jim C

如果第二个dom if依赖于从第一个dom if块中获取的值,那么嵌套/内部dom是否可能

  •  0
  • Jim C  · 技术社区  · 6 年前

    我仔细看了这些线

    Polymer 1 nested dom-if within dom-repeat not updating when data changes

    how to dynamically append an element to dom-if in Polymer?

    How to access content of dom-if inside a custom element?

    这可能与我的问题有关,但我没有找到任何线索,如果我能做我想做的和如何做。

    在我的公司中,有几个流程,每个流程对应于每个业务流程,流程的每个步骤都是一个屏幕,代码为Polymer1Web组件。它们都是在一个根聚合物组分中被加热的,这个组分定义了路径。

    一个简单的例子是:

    my-root-component:
    
    <dom-module id="my-root-component">
        <template>
            <first-obrigatiory-page which-route={aValueReturnedFromFirstComponent}></first-obrigatiory-page>
            <template is="dom-if" if="[[_isTrueFunction(aValueReturnedFromFirstComponent)]]" restamp>
                <second-page which-sub-route={aValueReturnedFromSecondComponent}></second-page>
                <template is="dom-if" if="[[_isTrueFunction(aValueReturnedFromSecondComponentComponent)]]" restamp>
                    <third-page ></third-page>
                </template>
            </template>
        </template>
    
            <script>
            Polymer({
                is: 'my-root-component',
                behaviors: [doesntMatterHere],
                properties: {
    

    第一个dom if按预期工作,但第二个dom似乎没有考虑在内,并且从未显示第三个页面组件。

    我检查过,IsTreeFunction的等效项(AvalueRetornedFromsecondComponent)返回true。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Rickard Elimää    6 年前

    aValueReturnedFromFirstComponent 实际返回任何内容,因为您应该将属性声明为 which-route="{{aValueReturnedFromFirstComponent}}" 而不是使用简单的 { } .

    是吗? whichRoute (注意camelcase)中的属性 first-obrigatiory-page 元素具有 notify: true 属性,所以变量实际发送回更新的值?


    每当dom ifs不更新时,我通常会在变量上设置观察器,这样我就可以查看它们是否真的更改,然后通过控制台使用 document.querySelector('my-root-component').set('aValueReturnedFromFirstComponent', true) 所以我可以看到dom如果真的更新了。

    解决方法可以是使用事件,但您所做的应该是有效的。