0

我想分享以下绑定/未绑定视图的片段以获得反馈。任何建议都将受到欢迎。

Yn.UnboundView = Em.View.extend({

  item: null,

  didInsertElement: function() {
    this._super();
    this.$().text( this.get('item') );

  }

});


Yn.BoundView = Em.View.extend({

  item: null,

  render: function(buffer) {
    buffer.push( this.get('item') );
  },

  _itemDidChange: Ember.observer(function() {
    this.rerender();
  }, 'item')

});
4

1 回答 1

1

这是更惯用的:

App.MyBoundView = Ember.View.extend({
    template: Ember.Handlebars.compile('Value: {{value}}'),
    valueBinding: 'App.myController.value'
});

或未绑定版本:

App.MyUnboundView = Ember.View.extend({
    template: Ember.Handlebars.compile('Value: {{unbound value}}'),
    valueBinding: 'App.myController.value'
});

甚至:

App.MyOtherUnboundView = Ember.View.extend({
    template: Ember.Handlebars.compile('Value: {{unbound value}}'),
    value: 42
});

示例@http://jsfiddle.net/MikeAski/GcUMu/

于 2012-06-07T08:03:47.210 回答