我仔细阅读了这些线程
聚合物1嵌套dom如果在dom内重复数据更改时不更新
如果在Polymer中,如何动态地将元素添加到dom?
如果在自定义元素中,如何访问dom的内容?
这可能与我的问题有关,但我没有找到任何线索,如果我能做我想做的事,以及如何做。
在我的公司中,有几个流程,每个流程对应于每个业务流程,流程的每个步骤都是一个编码为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按预期工作,但第二个似乎没有被考虑在内,我的第三个页面组件从未显示。
我检查了_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真的更新了。
解决方法可以是使用事件,但您所做的应该有效。