简体   繁体   English

如何在Ember.view上附加按钮的innerHTML

[英]How to append innerHTML of a button on Ember.view

I have created a view for button. 我已经创建了一个按钮视图。

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

My button model is 我的按钮型号是

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',

} ] }]

How can i pass the value of the button to the view from the controller. 如何从控制器将按钮的值传递给视图。

We can do it by adding tags and appending the innerHTML. 我们可以通过添加标签并附加innerHTML来实现。 But how to append the innerHTML in the buttonView from model through controller 但是如何从模型到控制器在buttonView中添加innerHTML

We can set the controller using 我们可以使用

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

to display the name use itemBinding 显示名称使用itemBinding

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

Now the value will get displayed in the view. 现在,该值将显示在视图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM