0

ここの両方の関数は「未定義」を返します。何が問題なのかわかりません..とても簡単に見えますか??

コントローラーでは、いくつかのプロパティを設定して、ユーザーに空のテキスト フィールドを表示し、ユーザーが独自のデータを確実に入力できるようにします。

Amber.ProductController = Ember.ObjectController.extend ({
    quantity_property: "",
    location_property: "",
    employee_name_property: "",

//quantitySubtract: function() {
//return this.get('quantity') -= this.get('quantity_property');
//}.property('quantity', 'quantity_property')

  quantitySubtract: Ember.computed('quantity', 'quantity_property', function() {
    return this.get('quantity') - this.get('quantity_property');
  });
});

ルートでは、employeeName と location の両方が設定されています...

Amber.ProductsUpdateRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.find('product', params.product_id);
  },
//This defines the actions that we want to expose to the template
  actions: {
    update: function() {
      var product = this.get('currentModel');
      var self = this; //ensures access to the transitionTo method inside the success (Promises) function
  /*  The first parameter to 'then' is the success handler where it transitions
      to the list of products, and the second parameter is our failure handler:
      A function that does nothing.  */
      product.set('employeeName', this.get('controller.employee_name_property'))
      product.set('location', this.get('controller.location_property'))
      product.set('quantity', this.get('controller.quantitySubtract()'))
      product.save().then(
        function() { self.transitionTo('products') },
        function() { }
      );
    }
  }
});

ハンドルバーには特別なものはありません

<h1>Produkt Forbrug</h1>
<form {{action "update" on="submit"}}>
   ...
<div>
  <label>
  Antal<br>
  {{input type="text" value=quantity_property}}
  </label>
  {{#each error in errors.quantity}}
    <p class="error">{{error.message}}</p>
  {{/each}}
</div>
<button type="update">Save</button>
</form>
4

2 に答える 2

0

を取り除く()

product.set('quantity', this.get('controller.quantitySubtract'))

そして、この方法は大丈夫でした:

quantitySubtract: function() {
  return this.get('quantity') - this.get('quantity_property');
}.property('quantity', 'quantity_property')

アップデート:

ルートを見ると、そのコントローラーはそのルートに適用されず、ジェネリックを使用しているだけEmber.ObjectControllerです。

Amber.ProductControllerに行くだろうAmber.ProductRoute

Amber.ProductUpdateControllerに行くだろうAmber.ProductUpdateRoute

両方のルートでコントローラーを再利用したい場合は、そのように製品コントローラーを拡張するだけです。

Amber.ProductController = Ember.ObjectController.extend ({
  quantity_property: "",
  location_property: "",
  employee_name_property: "",

  quantitySubtract: function() {
    return this.get('quantity') - this.get('quantity_property');
  }.property('quantity', 'quantity_property')
});

Amber.ProductUpdateController = Amber.ProductController.extend();
于 2014-10-28T15:58:54.400 に答える
0

私は関数をスキップしてしまい、代わりにこれを行います:

product.set('quantity', 
  this.get('controller.quantity') - this.get('controller.quantity_property'))

なぜその機能を使用できなかったのか、まだわかりません..コントローラーの名前を変更しようとしました..しかし、それは問題ではありませんでした..前に述べたように、コントローラーにフェッチする他の2つの値...

とにかく、私を助けてくれてありがとう!

于 2014-10-28T18:04:24.633 に答える