2017-08-03 13 views
0

私はGridPanel上のレコードを削除するDelete関数を定義しましたが、何とか何もしません!デバッグ中にはrec.destroyセクションが来て、コードブロック全体をスキップします。エラーなし、XHR要求なし、何もありません。削除機能がExtJS 5.1.1で動作しない

rec変数が読み込まれていないが、逆にそれが必要なデータを取得している可能性があります。

どうしてですか? (ちょうど@ scebotari66の提案後)

doDeleteEmployee: function() { 
var me = this; 
var rec = me.getEmployeeForm().getRecord(); 
Ext.MessageBox.confirm('Confirm Delete User', 'Are you sure you want to delete user ' + rec.get('firstName') + '?', function (btn) { 
    if (btn === 'yes') { 
     rec.erase({ 
       success: function(rec, operation) { 
        console.log('success step one'); 
        me.getStore().load(); 
        console.log('success step two'); 
        Ext.MessageBox.alert('INFO', 'Delete Success'); 
       }, 
       failure: function(rec, operation) { 
        console.log('this is failure'); 
        Ext.MessageBox.alert('Delete Failure', operation.request.scope.reader.jsonData.msg); 
       } 
     }); 
    } 
}); 

}

EDIT

まだ取得中にエラーが後消去方法を定義します。

私はeraseのためのアイデアを得た(私は上記の「doDeleteEmployee」関数を更新しました)が、デバッグ工程の後に、この結果:
1.デバッグ時には、それはrec.eraseに来て、その内部に、残りのブロックをスキップ。私はステップバイステップで試してみたとき、私は気づいた; afterDrop()の機能がのext-debug .jsまで正しいデータを保持します。
2.上記の2つのconsole.logを定義しました。の「成功ステップ1」のみが表示されます。
3. Dev-Tool'sのNetworkタブにXHRリクエストがありますが、どういうわけかHTTP:POSTメソッドで送信され、200-OKを応答として取得します。だから私は、おそらく私はモデルで何か間違っていると思って、下に追加しました。

エラー:

Uncaught TypeError: Cannot read property 'indexOf' of undefined 

がモデル:

Ext.define('Employee.model.EmployeeMdl', { 
     extend: 'Ext.data.Model', 
    requires: ['Ext.data.identifier.Sequential'], 
    identifier: { 
     type: 'sequential', 
     seed: 1223334477, 
     increment: 10 
    }, 
    fields: [ 
     {name: 'firstName', type: 'string'}, 
     {name: 'lastName', type: 'string'}, 
     {name: 'email', type: 'string'} 
    ], 
    idProperty: 'id', 
    proxy: { 
     type: 'ajax', 
     headers: { 
      'Content-Type': 'application/json'  
     }, 
     api: { 
      read: 'http://...0.223:8223/orest/employee', 
      create: 'http://...0.223:8223/orest/employee', 
      update: 'http://...0.223:8223/orest/employee', 
      destroy: 'http://...0.223:8223/orest/employee' 
     }, 
     reader: { 
      type: 'json' 
     }, 
     writer: { 
      type: 'json', 
      allowSingle: true, 
      encode: false, 
      writeAllFields: true 
     } 
    } 
}); 

答えて

2

プロキシを経由して、レコードを破棄したい場合は、eraseメソッドを使用する必要があります。

destroyメソッドは、Ext.BaseからExt.data.Modelに継承され、通常はモデルを処理するときには直接呼び出されません。あなたがエラーを取得しているので、コードの残りの部分をスキップし

  1. 更新

    This method is called to cleanup an object and its resources. After calling this method, the object should not be used any further.

  2. 応答が成功すると、successコールバックが呼び出されます。
  3. 通常はPOSTリクエストを送信します。これがajaxプロキシの仕組みです。これをカスタマイズしたい場合は、actionMethods設定を見てください。

Mapping of action name to HTTP request method. In the basic AjaxProxy these are set to 'GET' for 'read' actions and 'POST' for 'create', 'update' and 'destroy' actions.

+0

親愛なる@ scebotari66ご返信ありがとうございます。コードスニペットに関するいくつかの情報を更新しました。あなたにそれを確認する時間があることを願っています。 –

+0

どのようにレコードを作成しますか。個別にロードするか、ストアをロードするときに作成されますか? – scebotari66

+0

DB上に作成したレコードを削除しようとしています。したがって、ストアをロードするときにレコードが作成されます。 –

関連する問題