1
var attr = DS.attr,
hasMany = DS.hasMany,
belongsTo = DS.belongsTo;

Admin.Category = DS.Model.extend({
    name: attr(),
    mstore: belongsTo('mstore')
});

console.log(mstore); // this is a PromiseObject object passed from "{{action createCategory mstore}}" tag
var newCategory = this.store.createRecord('category', {
    name: 'nn',
    mstore: mstore
});

次のようなエラーが表示されます: アサーションに失敗しました: この関係には「mstore」レコードのみを追加できます。

PromiseObject オブジェクトを使用して属しているプロパティを設定するにはどうすればよいですか? ありがとう。

4

1 に答える 1

1

{{action...}} では、promise ではなく、実際のモデルを渡す必要があります。promise からモデルを取得するには、次のようにする必要があります。

var myMstore;

that.store.find('mstore', mstoreId).then(function(mstore) {
  myMstore = mstore;
});
于 2013-10-04T16:00:10.717 に答える