如何在 Ember.view 上附加按钮的内部 HTML

How to append innerHTML of a button on Ember.view

本文关键字:按钮 内部 HTML Ember view      更新时间:2023-09-26

我已经为按钮创建了一个视图。

App.NumberButtonView = Ember.View.extend({
tagName: 'button',
classNames: ['ButtonClass']
});

我的按钮型号是

App.NumberBtns = DS.Model.extend({
value: DS.attr('string'),
width: DS.attr('string'),
height: DS.attr('string'),
className: DS.attr('string'),
type:DS.attr('string')

})

App.NumberBtns.FIXTURES = [  {
id: '108',
value: '8',
style: {
    width: '50px',
    height: '50px'
},
className: 'NumberBtnClass',
type: 'number',
}, {
id: '109',
value: '9',
style: {
    width: '50px',
    height: '50px'
},
className: 'NumberBtnClass',
type: 'number',
}, {
id: '110',
value: '0',
style: {
    width: '50px',
    height: '50px'
},
className: 'NumberBtnClass',
type: 'number',

}]

如何将按钮的值从控制器传递给视图。

我们可以通过添加标签并附加 innerHTML 来做到这一点。但是如何在按钮中附加内部 HTML 从模型到控制器查看

我们可以使用以下方法设置控制器

setupController: function (controller, model) {
    controller.set('model', model);

显示名称使用项绑定

{{#each btn in model.operatorBtn}}
{{#view App.NumberButtonView itemBinding="btn"}}
<i> {{view.item.value}} </i>
{{/view}}
 {{/view}}
 {{/each}

现在,该值将显示在视图中。