【问题标题】:How to append innerHTML of a button on Ember.view如何在 Ember.view 上附加按钮的 innerHTML
【发布时间】:2015-09-06 08:06:34
【问题描述】:

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

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 来实现。但是如何通过控制器在模型中的 buttonView 中附加 innerHTML

【问题讨论】:

    标签: javascript jquery html model-view-controller ember.js


    【解决方案1】:

    我们可以设置控制器使用

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

    使用 itemBinding 显示名称

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 2018-04-05
      • 1970-01-01
      • 2015-10-12
      • 2021-11-13
      • 2020-03-16
      • 2014-01-22
      相关资源
      最近更新 更多