有人可以提供一个正确实现 dom-if
的例子吗?
official documentation 没有提供正确使用的示例. (抱歉,没有直接链接。必须使用左上角的菜单并选择 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
的函数。
关于javascript - polymer 1.0 : Help using dom-if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31511727/