繁体   English   中英

是否有可能嵌套/内部dom-if,其中第二个dom-if取决于从第一个dom-if块获得的值

[英]is it possible nest/inner dom-if where the second dom-if depends on value oberseved from the first dom-if block

我仔细阅读了这些主题

数据重复时,聚合物1嵌套的dom-如果dom-rep中不更新

如何在Polymer中将元素动态附加到dom-if?

如何在自定义元素中访问dom-if的内容?

这可能与我的问题有关,但我没有找到任何线索,说明我是否可以做自己想做的事情和如何做的事情。

在我的公司中,有多个流程,每个流程对应一个业务流程,流程的每个步骤都是一个屏幕,编码为Polymer 1 Web组件。 它们全部包裹在定义路线的聚合物根成分中。

一个简单的例子是:

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-if似乎没有考虑到,而且我的第三页组件也从未显示。

我检查了_isTrueFunction(aValueReturnedFromSecondComponentComponent)的等效值是否返回true。

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

first-obrigatiory-page元素中的whichRoute (请注意camelCase)属性是否具有notify: true属性,因此该变量实际上发回了更新后的值?


我通常在不更新dom-if的时候就对变量设置观察者,这样我就可以查看它们是否真的改变了,然后我自己通过控制台使用document.querySelector('my-root-component').set('aValueReturnedFromFirstComponent', true)因此我可以看到dom-if确实在更新。

解决方法可能是使用事件,但是您所做的应该可行。

使用

[英]Using <template is=“dom-if” with a condition

暂无
暂无

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

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