【发布时间】:2016-09-15 10:39:44
【问题描述】:
我在 Blaze 中有一个 buttons 的动态模板,看起来像这样(简化):
button.html
<template name="Button">
<button {{attributes}}>
<span class="button__text">{{> UI.contentBlock}}</span>
</button>
</template>
button.js
import {Template} from 'meteor/templating';
import cx from 'classnames';
import './button.html';
Template.Button.helpers({
attributes() {
const instance = Template.instance();
let {data} = instance;
return {
disabled: data.disabled,
'class': cx('button', data.class)
};
}
});
尝试设置动态数据属性:
{{#Button class="js-add-contact" data-phase-index={{index}}}}Add Contact{{/Button}}
在data-phase-index 中插入index(假设它只是一个简单的动态字符串)会引发错误:内容块不期望{{。我不确定将动态数据放入模板的另一种方法。还有一个问题是让attributes() 助手中的Button 识别data- 属性。谁能解决这个问题?
【问题讨论】:
-
你能不能把
index的值放到一个helper 中并在attrdata-phase-index=getIndex中引用它?这在Template.dynamics 对我有用。 -
@CodeMonkey 感谢您的输入,index 实际上是一个帮手,我只是犯了一个愚蠢的错误!
标签: meteor meteor-blaze