【问题标题】:EmberJs: component templateEmberJs:组件模板
【发布时间】:2012-12-12 02:44:10
【问题描述】:

我尝试从 http://www.eyecon.ro/bootstrap-colorpicker/ 包装一个 colorPicker 组件
我需要用视图的“值”属性填充模板的“背景颜色 css 属性”... 我尝试设置 {{value}} 但它不起作用...

有什么建议吗?

JavaScript:

App.ColorPicker = Em.View.extend({
      classNames: 'input-append color',
      attributeBindings: ['name', 'value'],
      value: '',
      template: Ember.Handlebars.compile('{{view Ember.TextField valueBinding="this.value"}}<span class="add-on"><i style="background-color: {{value}}"></i></span>'),
      didInsertElement: function() {
            $('#backgroundColor').colorpicker({format: "rgb"});
      }
    })

;

html:

{{view App.ColorPicker placeholder="Background color" name="backgroundColor" valueBinding="App.controller" classNames="input-large" id="backgroundColor"}}

【问题讨论】:

  • 试试 valueBinding="view.value" 而不是 "this.value"
  • 使用 view.value 我得到以下结果:
  • 你能发个小提琴什么的吗,因为这样很难调试!
  • 我的第一个 github :) github.com/fvisticot/colorpicker.git

标签: ember.js


【解决方案1】:

您需要查看 {{bindAttr}} 助手。上面有一篇旧但很好的帖子here

基本上,您不能只将绑定值放入 HTML 标记中,因为它会插入包装脚本标记并破坏所有内容。

您正在寻找的是:

App.ColorPicker = Em.View.extend({
  classNames: 'input-append color',
  attributeBindings: ['name', 'value'],
  value: '',
  template: Ember.Handlebars.compile('{{view Ember.TextField valueBinding="this.value"}}<span class="add-on"><i {{bindAttr style="view.iStyle"}}></i></span>'),
  iStyle: function() {
    return "background-color:" + this.get('value');
  }.property('value'),
  didInsertElement: function() {
    $('#backgroundColor').colorpicker({format: "rgb"});
  }
});

【讨论】:

  • 发送很多!工作正常。我认为 iStyle 函数应该返回“背景颜色”...
  • 你说得对,变了,我是个咖啡师,所以这些天我变回来的时候总是忘记放回报
猜你喜欢
  • 2015-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多