簡體   English   中英

Polymer dom-if:如何實現負面條件?

[英]Polymer dom-if: how do I implement a negative condition?

我有一個Polymer元素,使用<template is="dom-if"...根據條件提供不同的HTML內容。

聚合物dom-if沒有其他條件,因此需要一個負的if條件來模擬它。

像這樣的東西:

 <link href="https://polygit.org/components/polymer/polymer.html" rel="import"> <dom-module id="test-thing"> <template> <template is="dom-if" if="{{title}}" restamp> <b>[[title]]</b> </template> <template is="dom-if" if="{{!title}}" restamp> <i>no title</i> </template> </template> <script> Polymer({ is: 'test-thing', properties: { title: String } }); </script> </dom-module> <div> With negative condition: <test-thing></test-thing> </div> <div> With positive condition: <test-thing title="Has Title"></test-thing> </div> 

只有這不起作用 - 負面條件永遠不會通過。

該如何實施?

您必須為title屬性使用默認空值:

  title:{type: String,value:''}

像這樣:

 <link href="https://polygit.org/components/polymer/polymer.html" rel="import"> <dom-module id="test-thing"> <template> <template is="dom-if" if="{{title}}" restamp> <b>[[title]]</b> </template> <template is="dom-if" if="{{!title}}" restamp> <i>no title</i> </template> </template> <script> Polymer({ is: 'test-thing', properties: { title: {type: String,value:''} } }); </script> </dom-module> <div> With negative condition: <test-thing></test-thing> </div> <div> With positive condition: <test-thing title="Has Title"></test-thing> </div> 

使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM