ember.js 1.0とember-data 1.0 beta2を使用
次のプロパティを持つモデル(状態)があります
state: DS.attr('string'),
stateName: DS.attr('string'),
および次のプロパティを持つモデル (顧客)
name: DS.attr('string'),
stateID: DS.attr('string'),
state: DS.belongsTo("state")
顧客を編集して、ドロップダウンから州を選択できるようにしたい (stateID + 名前が表示されている: たとえば、「フロリダ - フロリダ」を選択し、state.stateID を customer.stateID プロパティに保存する)
このようなことを試したのはこれが初めてで、プロセスについて少し混乱しています。
私の顧客ルートでは、次のように設定しました。
setupController: function(controller, model) {
this._super(controller, model);
this.controllerFor('state').set('content', this.store.find('state'));
}
そして私の選択はこれです:
{{view Ember.Select
contentBinding="controllers.state.content"
optionValuePath="content.stateName"
optionLabelPath="content.stateName"
valueBinding="content.stateID"
selectionBinding="content.stateID"
prompt="Select a state"
}}
今、私はここからどこへ行こうか迷っています。
ありがとう
アップデート
と言う見方を変えた
{{view Ember.Select
contentBinding="controllers.state.content"
optionValuePath="content.stateID"
optionLabelPath="content.stateName"
valueBinding="customer.stateID"
}}
そして、私はまだ stateid プロパティを変更できません。私も試してみました
selectionBinding="customer"
無駄に。
アップデート #2
私の問題は、プロパティ名に関連している可能性があると思われます。customer.stateID プロパティを customer.foobar に変更し、select を read に変更しました
{{view Ember.Select
contentBinding="controllers.state.content"
optionValuePath="content.stateName"
optionLabelPath="content.stateName"
valueBinding="foobar"
class="form-control"
}}
そして今、customer.foobar は選択からの値で更新されます。
customer の stateID というプロパティに問題はありますか? 私は状態モデルと状態コントローラーなどを持っているので、競合はありますか?