簡體   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