2011-01-13 22 views
0

不觸發createRecord新對象在我響應,我有:在數據源

Spanish.ADDWORD = SC.Responder.create({ 

    didBecomeFirstResponder: function(responder) { 
    var store = this._store = Spanish.store.chain(); //buffer changes 
    var word = store.createRecord(Spanish.Word, {word: "", english: ""}); 
    Spanish.addWordController.set("content",word); 

    //show the dialog 
    var pane = Spanish.getPath('addWordPage.mainPane'); 
    pane.append(); 
    pane.makeFirstResponder(); 
    },  

    submit: function(){ 
    this._store.commitChanges().destroy(); 
    Spanish.makeFirstResponder(Spanish.READY); 
    } 
} 

之前,我有數據源鉤取,我用的地方,一切正常。當我點擊提交時,沒有創建新的對象,並且createRecord沒有被調用。

回答

1

一個可能的問題是您正在調用.destroy()。這不應該成爲一個問題,但正如你所說的,它在使用燈具(同步)時正在工作。現在你正在使用一個dataSource(通常是異步的),它可能會被打斷。嘗試刪除.destory(),並查看是否解決了您的問題。

另一個嘗試的方法是,嵌套存儲中可能存在一個錯誤,因爲如果您創建新記錄(而不是編輯現有記錄),則「更改了」測試可能會失敗(因爲那裏也沒什麼可比性的),所以調用commitChanges(YES)會強制一次提交,而沒有檢查。

+0

添加「Spanish.store.commitRecords();」使它工作! – LDK 2011-01-13 22:57:16