2

ember.js 1.0ember-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 というプロパティに問題はありますか? 私は状態モデルと状態コントローラーなどを持っているので、競合はありますか?

4

2 に答える 2

1

結局のところ、問題はモデル自体にありました。状態モデルには stateID フィールドがありません。これは state.state ... です。

このために時間を無駄にしてしまったすべての人に、心からお詫び申し上げます。そのようなばかげたエラー。

于 2013-09-10T06:04:52.403 に答える
0

わかりました、おそらく最善の解決策ではありませんが、うまく機能します:

App.ItemModalController = Ember.ObjectController.extend({
  content: [],

  availableCategories: function() {
    return this.store.find('category');
  }.property(),

  //...
});

そして選択:

{{view Ember.Select
  contentBinding="availableCategories"
  valueBinding="categorySelected"
  optionLabelPath="content.title"
  optionValuePath="content.id"
  prompt="Please select a category"
  class="form-control"
}}
于 2013-09-09T13:43:42.527 に答える