我已經繼承了構建在Rails API之上的Ember.js應用程序。使用餘燼護欄寶石Ember Rails模型關係
Ember : 1.7.1+pre.f095a455 ember.js
DEBUG: Ember Data : 1.0.0-beta.10+canary.30d6bf849b ember.js
DEBUG: Handlebars : 1.3.0 ember.js
:這是最初運行以下:
Ember.VERSION : 1.0.0 ember.js
DEBUG: Handlebars.VERSION : 1.0.0 ember.js
DEBUG: jQuery.VERSION : 1.10.2
但這些都已經更新到以下。
我在嘗試保存剖面模型時陷入了一個大阻滯問題。每個部分都有與該行模型的關係:
row: DS.belongsTo('row', { async: true })
,作爲回報,該行模型:
sections: DS.hasMany('section', { async: true })
保存一個新的部分運行在一個控制器下面的函數。在將對象發送到createRecord方法之前,行類正在發送並應用於對象。
_createSection: function(row, new_section_data){
var store = this.get('store');
new_section_data.width = this.getNewSectionWidth(row);
new_section_data.position = this.getNewSectionPosition(row);
new_section_data.row = row;
var new_section = store.createRecord('section', new_section_data);
console.log(' returned new_section ');
console.log(new_section);
new_section.save().then(function() {
console.log('saved');
new_section.set('set_as_selected', true);
console.log(' new_section post save ');
console.log(new_section);
}, function() {
console.log('new section save failure');
});
return new_section;
},
只要模型創建就存在問題。該行實際上並未正確應用於模型,因此Rails API請求無法正常工作,並且該部分未被保存。
在之前的createRecord請求new_section對象保存的數據是如下:
html: "<p>New section</p>"
position: 3
row: Class
section_type_type: "TextSection"
width: 6
這是附着在上面的代碼的行類(具有擴展_data節點):
__ember1414408746094: "ember791"
__ember_meta__: Object
__nextSuper: undefined
_attributes: Object
_changesToSync: Object
_data: Object
id: 1
page: Class
page_id: 1
position: 1
sections: Array[2]
style: null
__proto__: Object
_deferredTriggers: Array[0]
_hasHadSections: true
_inFlightAttributes: Object
_relationships: Object
_updatingRecordArraysLater: false
container: Container
currentState: Object
defaultStyleObject: Object
id: "1"
store: Class
updateTimeout: 7
__proto__: Class
section_type_type: "TextSection"
width: 6
但是,以下是返回的new_section變量的_data節點:
_data: Object
contact_form_fields: Array[0]
created_at: "2014-10-27T11:14:39.000Z"
deleted_at: null
gallery_images: Array[0]
heading_visible: false
height: null
html: "<p>New section</p>"
id: 21
position: 3
row: null
section_type_id: 19
section_type_type: "TextSection"
style: null
updated_at: "2014-10-27T11:14:39.000Z"
width: 6
在這裏您可以看到行值爲空。
我有困難(大)試圖找出這個問題發生的地方。這可能與Ember數據更新(這最初是使用更老的版本構建的)相關,但是我恐怕沒有知識來了解發生了什麼變化以及發生了什麼。
任何人都可以提供的幫助將是非常有用的,謝謝。您正在尋找在錯誤的地方尋找row