[英]Polymer 1.0: Help using dom-if
有人可以提供正確實施dom-if
的示例嗎?
官方文檔沒有提供正確使用的示例。 (對不起,沒有直接鏈接。必須使用左上角的菜單並選擇dom-if
)。
這是我到目前為止所擁有的。 顯然,它不起作用。
<template>
...
<template is="dom-if" if="{{action}}=='Login'">
<!-- Also tried: if="{{action=='Login'}}" -->
<a href="#">Forgot password?</a>
</template>
...
</template>
這很麻煩,但你必須這樣做:
<template is="dom-if" if="[[_actionIsLogin(action)]]">
<a href="#">Forgot password?</a>
</template>
<script>
Polymer({
...
_actionIsLogin: function(action) {
return action === 'Login';
}
...
});
</script>
顯式創建一個返回true
或false
的函數。
我認為以下示例非常直接且易於理解/實現(它不在您提供的鏈接中):
https://www.polymer-project.org/1.0/docs/devguide/templates.html
從頁面...
<div>{{user.name}}</div>
<template is="dom-if" if="{{user.isAdmin}}">
Only admins will see this.
<div>{{user.secretAdminStuff}}</div>
</template>
...
希望能幫助到你。
<template>
<iron-ajax
auto
url="https://jsonplaceholder.typicode.com/todos"
handle-as="json"
last-response="{{baul}}">
</iron-ajax>
<template is="dom-repeat" items="{{baul}}" >
<template is="dom-if" if="{{item.completed}}">{{item.title}} is completed<br></template>
</template>
</template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.