简体   繁体   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

I read carefully these threads 我仔细阅读了这些主题

Polymer 1 nested dom-if within dom-repeat not updating when data changes 数据重复时,聚合物1嵌套的dom-如果dom-rep中不更新

how to dynamically append an element to dom-if in Polymer? 如何在Polymer中将元素动态附加到dom-if?

How to access content of dom-if inside a custom element? 如何在自定义元素中访问dom-if的内容?

that may have some relation with my question but I didn't manage find any clue if I can do what I want and how. 这可能与我的问题有关,但我没有找到任何线索,说明我是否可以做自己想做的事情和如何做的事情。

In my company, there are several flows, each one for each business flow and each step of the flow is a screen coded as a Polymer 1 web component. 在我的公司中,有多个流程,每个流程对应一个业务流程,流程的每个步骤都是一个屏幕,编码为Polymer 1 Web组件。 All them are warraped in a root Polymer component which defines the route. 它们全部包裹在定义路线的聚合物根成分中。

A simple exemple would be: 一个简单的例子是:

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: {

The first dom-if works as expected but the second seems not be taken in account and my third-page component is never showed. 第一个dom-if可以正常工作,但是第二个dom-if似乎没有考虑到,而且我的第三页组件也从未显示。

I checked and the equivalent for _isTrueFunction(aValueReturnedFromSecondComponentComponent) is returning true. 我检查了_isTrueFunction(aValueReturnedFromSecondComponentComponent)的等效值是否返回true。

Does aValueReturnedFromFirstComponent really return anything, because you should declare the attribute as which-route="{{aValueReturnedFromFirstComponent}}" instead of using simple { } . aValueReturnedFromFirstComponent确实返回任何内容吗,因为您应将属性声明为which-route="{{aValueReturnedFromFirstComponent}}"而不是使用简单的{ }

Does the whichRoute (note the camelCase) property in the first-obrigatiory-page element have the notify: true property so the variable actually sends back the updated value? first-obrigatiory-page元素中的whichRoute (请注意camelCase)属性是否具有notify: true属性,因此该变量实际上发回了更新后的值?


I usually set observers on variables whenever dom-ifs don't update so I can see if they really change or not, and then set the variables myself through the console with document.querySelector('my-root-component').set('aValueReturnedFromFirstComponent', true) so I can see that the dom-if really updates. 我通常在不更新dom-if的时候就对变量设置观察者,这样我就可以查看它们是否真的改变了,然后我自己通过控制台使用document.querySelector('my-root-component').set('aValueReturnedFromFirstComponent', true)因此我可以看到dom-if确实在更新。

A workaround could be to use events, but what you've done should work. 解决方法可能是使用事件,但是您所做的应该可行。

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

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