简体   繁体   English

聚合物dom-如果不起作用

[英]Polymer dom-if not working

I have this template dom-if using Polymer 1.X, and it is not working. 如果使用Polymer 1.X,我有此模板dom-,但无法正常工作。

It is supposed to display 'Loading' when requirement.allLoaded is false and display the real content when requirement.allLoaded is true . 它应该显示“正在载入”当requirement.allLoadedfalse时,并显示真正的内容requirement.allLoadedtrue

I switch the state of this variable in my test function. 我在测试函数中切换此变量的状态。 But it doesn't take effects. 但这并没有效果。

 //Properties requirement: { type:Object, value: { allLoaded: false, tagsLoaded: false } } //Test function _testButton: function(){ console.log(this.requirement); this.requirement.allLoaded = !this.requirement.allLoaded; console.log(this.requirement); }, 
 <div id="modal-content"> <template is="dom-if" if={{!requirement.allLoaded}}> <p>Loading</p> </template> <template is="dom-if" if={{requirement.allLoaded}}> <iron-pages selected="[[selectedTab]]" attr-for-selected="name" role="main"> <details-tab name="details"></details-tab> <bar-chart-tab name="barchart"></bar-chart-tab> <live-data-tab name="livedata" shared-info='{{sharedInfo}}'></live-data-tab> </iron-pages> </template> </div> 

Note: I already used this structure to display/not display things in other project (with Polymer 2) and it was working. 注意:我已经使用此结构来显示/不显示其他项目(使用Polymer 2),并且它正在工作。

Is it only the change that does not work? 仅仅是改变不起作用? Ie it shows correctly on load? 即它可以正确显示负载?

Try notifying Polymer of the change: this.requirement.allLoaded = !this.requirement.allLoaded; this.notifyPath('requirement.allLoaded'); 尝试通知聚合物更改: this.requirement.allLoaded = !this.requirement.allLoaded; this.notifyPath('requirement.allLoaded'); this.requirement.allLoaded = !this.requirement.allLoaded; this.notifyPath('requirement.allLoaded');

You could also use this.set('property.subProperty', value) for Observable Changes . 您还可以将this.set('property.subProperty', value)用于可观察的更改
In your case, that's this.set('requirement.allLoaded', !this.requirement.allLoaded); 在您的情况下,这是this.set('requirement.allLoaded', !this.requirement.allLoaded);

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

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