2013-02-01 88 views
0

我正在研究Ember.js类来帮助处理表单。在下面的片段中,我的widget的定义需要绑定到它的value,以便嵌套它的对象的属性,因此我将绑定设置为'App.AjaxForm.aField.value'如何在嵌套对象定义中引用Ember.js对象?

有没有一个不太重复的方式来说这个?

App.Field = Ember.Object.extend({ 
    // The Ember.js equivalent of ``django.forms.fields.Field``. 
    value: null, 
    errors: [], 
    widget: null 
}); 

App.AjaxForm = App.Form.create({ 
    action: '/ajax/', 
    fields: [ 
     'aField' 
    ], 
    aField: App.Field.create({ 
     widget: Ember.TextField.extend({ 
      valueBinding: 'App.AjaxForm.aField.value' 
     }) 
    }) 
}); 

更新:增加了App.Field的定义。

+0

这个问题有点混乱(至少对我来说)。你想要的东西像valueBinding:'parentView.value'。不知道你是如何实现App.Field将很难给出完整的答案。 –

+0

@CoryLoken我想'parentView.value'是类似于我想要的。我用'App.Field'的定义更新了这个问题。它只是一个具有几个属性的Ember对象。 – hekevintran

回答

0

这是我的解决方案。

App.Field = Ember.Object.extend({ 
    // The Ember.js equivalent of ``django.forms.fields.Field``. 
    value: null, 
    errors: [], 
    widget_class: Ember.TextField, 
    widget: function() { 
     return this.get('widget_class').extend({ 
      field: this, 
      valueBinding: 'field.value' 
     }); 
    }.property() 
});