2013-03-16 8 views
6

मैं निम्न त्रुटि जब चयनित पंक्ति प्राप्त करने की कोशिश हो रही है करना:ExtJS ग्रिड हटाएँ पंक्ति - चयनित पंक्ति

Uncaught TypeError: Object #<HTMLDivElement> has no method 'getView' 

कैसे वर्तमान चयनित पंक्ति मिलता है जब मैं दृश्य और इसलिए नहीं मिल सकता है SelectionModel?

मेरे देखें कोड:

Ext.define('MyLodge.view.content.MemberGrid', { 
extend: 'Ext.grid.Panel', 
alias: 'widget.membergrid', 



initComponent: function(){ 

    var rowEditing = Ext.create('Ext.grid.plugin.RowEditing'); 

    var store = Ext.create('MyLodge.store.Members'); 

    Ext.apply(this, { 
     height: this.height, 
     plugins: [rowEditing], 
     store: store, 
     stripeRows: true, 
     columnLines: true, 
     columns: [{ 
      id  :'id', 
      text: 'ID', 
      width: 40, 
      sortable: true, 
      dataIndex: 'id' 
     },{ 
      text : 'Name', 
      flex: 1, 
      sortable : true, 
      dataIndex: 'name', 
      field: { 
       xtype: 'textfield' 
      } 
     },{ 
      text : 'E-Mail', 
      width : 150, 
      sortable : true, 
      dataIndex: 'email', 
      field: { 
       xtype: 'textfield' 
      } 
     },{ 
      text : 'Href', 
      width : 200, 
      editable: false, 
      sortable : true, 
      dataIndex: 'href' 
     }], 
     dockedItems: [{ 
      xtype: 'toolbar', 
      items: [{ 
       text: 'Add', 
       iconCls: 'icon-add', 
       handler: function(){ 
        // empty record 
        store.insert(0, new MyLodge.model.Member()); 
        rowEditing.startEdit(0, 0); 
       } 
      }, { 
       text: 'Delete', 
       iconCls: 'icon-delete', 
       handler: function(){ 
        var selection = grid.getView().getSelectionModel().getSelection()[0]; 
        if (selection) { 
         store.remove(selection); 
        } 
       } 
      },'-',{ 
       text: 'Save', 
       iconCls: 'icon-save', 
       handler: function(){ 
        store.sync({ 
         success: function(response){ 
          store.load() 
         } 
        }); 

       } 
      },{ 
       text: 'Refresh', 
       handler: function(){ 
        store.load(); 
       } 
      }] 
     }] 
    }); 

    this.callParent(arguments); 
    } 
}); 

उत्तर

9

एक विकल्प एक चर के रूप में बंद करने के लिए scope जोड़ने की जाएगी तो अपने हैंडलर में आप me उपयोग कर सकते हैं ग्रिड का उल्लेख करने के:

{ 
    text: 'Delete', 
    iconCls: 'icon - delete ', 
    handler: function() { 
     var selection = me.getView().getSelectionModel().getSelection()[0]; 
     if (selection) { 
      store.remove(selection); 
     } 
    } 
} 

कार्य उदाहरण:http://jsfiddle.net/Sn4fC/


एक दूसरा विकल्प handler के बजाय एक clicklistener की स्थापना की जा सकती है और scope को निर्दिष्ट:

{ 
    text: 'Delete', 
    iconCls: 'icon - delete ', 
    listeners: { 
     click: { 
      scope: this, 
      fn: function() { 
       var selection = this.getView().getSelectionModel().getSelection()[0]; 
       if (selection) { 
        store.remove(selection); 
       } 
      } 
     } 
    } 
} 

कार्य उदाहरण:http://jsfiddle.net/XyBbF/

1

मुद्दा यह है कि 'ग्रिड' हैंडलर समारोह दायरे में उपलब्ध नहीं है या यह एक क्या आप वास्तव में यह उम्मीद होने के लिए नहीं है।

handler: function(){ 
     //.... keep the debug point here in browser developer tool and verify the value of grid in console. It is definitely not an instance of the grid u expected hence it wont have getView() method. 
     var selection = grid.getView().getSelectionModel().getSelection()[0]; 

} 

ग्रिड के संदर्भ में हो रही कोशिश करो और हैंडलर में इसका इस्तेमाल करते हैं जिन्हें आप नीचे देख:

initComponent: function() { 
    var me = this; 
    . 
    . 

:

Ext.define('MyLodge.view.content.MemberGrid', { 
    extend: 'Ext.grid.Panel', 
    alias: 'widget.membergrid', 
    id: 'membergrid', 
    ...... 

handler: function(){ 
    var grid = Ext.getCmp('membergrid'); // where 'membergrid' is the id defined in grid config 
    var selection = grid.getView()...... 
+0

CD..User के जवाब मेरे एक से एकदम सही है !!! – Srikanth

+0

आपका जवाब काम कर किया जा सकता है, लेकिन [jsfiddle] के माध्यम से उदाहरण की आपूर्ति (http://jsfiddle.net) काफी बेहतर है। –

संबंधित मुद्दे