【发布时间】:2015-01-27 10:21:20
【问题描述】:
我正在将一些 html 传递给 ember 中的组件。 html 已生成。 但是生成的 html 无法访问组件中定义的属性。但是,这些属性确实适用于组件模板。
组件
import Ember from 'ember';
export default Ember.Component.extend({
user: undefined,
replyText: undefined,
onInitialization: function(){
this.set('replyText', '@' + this.user.get('username') + ' ');
}.on("init"),
remainingTweetChars: function () {
var length = 140 - this.get('replyText').length;
return length;
}.property('replyText')
});
组件模板
{{remainingTweetChars}} {{!-- this works --}}
{{yield}}
在上面的组件模板中生成的 html 组件使用
{{#action-reply class="item-actionables__reply"
user=user
}}
<span>{{remainingTweetChars}}</span> {{!-- this does NOT works --}}
<span>{{view.remainingTweetChars}}</span> {{!-- this does NOT works --}}
{{/action-reply}}
【问题讨论】:
标签: ember.js ember-data handlebars.js ember-components