如何在自动绑定模板(即声明为 的模板<template is='dom-bind'>...</template>
)中定义计算绑定?
问问题
1532 次
1 回答
6
只需通过脚本将计算绑定直接分配给模板元素,确保在定义计算绑定之后初始化所涉及的属性。
例子:
<template is="dom-bind">
<div>
<input value="{{text::input}}">
</div>
<div>[[describe(text)]]</div>
</template>
<script>
(function() {
var template = document.querySelector('template[is="dom-bind"]');
template.describe = function(text) {
if (text) {
return 'You entered "' + text + '", which is ' + text.length + ' characters long.';
} else {
return 'You didn\'t even enter a thing! Shame on you.';
}
};
template.text = '';
})();
</script>
于 2015-06-12T21:52:30.450 回答