2014-12-30 30 views
3
DEBUG: ------------------------------- ember-1.9.1.js:3935 
DEBUG: Ember  : 1.9.1 ember-1.9.1.js:3935 
DEBUG: Ember Data : <%= versionStamp %> ember-1.9.1.js:3935 
DEBUG: Handlebars : 2.0.0 ember-1.9.1.js:3935 
DEBUG: jQuery  : 1.11.1 ember-1.9.1.js:3935 
DEBUG: ------------------------------- 

我必須模型就像這樣:我如何可以回滾一個屬於關聯模型

Hwv.Car = DS.Model.extend({ 
    number: DS.attr('string'), 
    owner: DS.belongsTo('user') 
}); 
Hwv.User = DS.Model.extend({ 
    name: DS.attr('string'), 
    phone: DS.attr('string'), 
    email: DS.attr('string') 
}); 

然後我在模板中使用的選擇輸入:

{{#if isEditing}} 
    {{view "select" id = "owner" class="form-control" 
    content=owners 
    optionLabelPath="content.name" 
    optionValuePath="content.id" 
    prompt="--please select a user--" 
    selection=selectedOwner 
    }} 
    <span class="glyphicon form-control-feedback"></span> 
{{else}} 
    <p class="form-control-static">{{owner.name}}</p> 
{{/if}} 

和我的控制器就像是這個:

Hwv.CarController = Ember.ObjectController.extend({ 
    needs:["application","session"], 
    isEditing:false, 
    isNew:false, 
    owners:function(){ 
     var model = this.get('model'), 
      store = this.store; 
     return store.filter('user', function (user) { 
      return true; 
     }); 
    }.property(), 
    selectedOwner:function(k,v){ 
     var model = this.get('model'); 
     if(!model){ 
      return; 
     } 
     if (v === undefined) { 
      return model.get("owner"); 
     } else { 
      debugger; 
      model.set('owner', v); 
      debugger; 
      return v; 
     } 
    }.property("model.owner"), 
    selectedOwnerDidChange: function() { 
     debugger; 
     //if i remove this row ,the car model can't be dirty when the owner of the car is changed by the select input. 
     this.get('model').send('becomeDirty'); 
    }.observes('selectedOwner'), 
    actions:{ 
     cancel:function(){ 
      //this row will work when i change the car number only and then click the cancel button 
      //but when i change the car owner by the select input,the car model can't rollback successfully. 
      this.get("model").rollback(); 
     } 
    } 
}); 

這個問題似乎指出該ember數據無法成功回滾belongsTo模型,並且即使在belongsTo屬性發生更改時,它也不能準確標記該模型的髒屬性。

我問:我怎樣才能解決與車主belongsTo模型的回滾問題就像上面。

回答

0

我在我們的網站上搜索了這個問題,但我找不到解決方案,其中一個就像 'How to rollback relationship changes in EmberData',在這種情況下,它有一個hasMany關係,但在我的情況下,只有一個belongsTo。

相關問題