2015-11-19 6 views
0

Как передать идентификатор из сетки в модель? вот мой код сетки панели:ext js 6 пропустить динамический идентификатор от сетки до модели

{ 
    text  : 'Tindakan', 
    xtype: 'actioncolumn', 
    minWidth: 130, 
    sortable: false, 
    menuDisabled: true, 
    items: [{ 
       icon: 'images/view.png', // Use a URL in the icon config 
       tooltip: 'Lihat', 

       handler : function(grid, rowIndex, colIndex) { 
       var rec = grid.getStore().getAt(rowIndex); 
       alert("Lihat - " + rec.get('id')); 

    }] 
} 

Вот мой код модели:

Ext.define('Kds.model.ProfilView', { 
    extend: 'Ext.data.Store', 

    alias: 'model.profilView', 

    fields: [ 
     'name', 
     'ic_no', 
     'address', 
    ], 

    pageSize : 20, 
    proxy: { 
     type: 'rest', 
     url : 'http://localhost/kds-rest/web/index.php/people/view/'+id, 
     useDefaultXhrHeader : false, 
     withCredentials: false, 
     reader: { 
      type: 'json', 
      rootProperty: 'data', 
      //totalProperty: 'totalItems' 

     } 
    }, 
    autoLoad: 'true', 
}); 

ответ

0

Как использовать эту модель? При создании или использовании, что каждый раз, вы можете попробовать это:

handler : function(grid, rowIndex, colIndex) { 
    var rec = grid.getStore().getAt(rowIndex); 
    //Create or get model to use 
    var model = Ext.create('Kds.model.ProfilView', { 
     // then give the record id to model 
     recordId: rec.get('id') // edited 
    }); 
} 



// to use in model 
    Ext.define('Kds.model.ProfilView', { 
    extend: 'Ext.data.Store', 
    alias: 'model.profilView', 
fields: [ 
    'name', 
    'ic_no', 
    'address' 
], 
pageSize : 20, 
autoLoad: 'true', 
    initComponent: function() { 
    var me = this; 
    me.proxy = { 
     type: 'rest', 
     url :  'http://localhost/kdsrest/web/index.php/people/view/'+me.recordId, // or this.up().recordId, 
     ................ 
    } // iniComponent 
    me.callParent(); 

Edit: Как загрузить модель динамически: скрипку: https://fiddle.sencha.com/#fiddle/11g9

Ext.define('model.instance', { 
    extend: 'Ext.data.Model', 
    fields: ['name', 'city', 'country'], 
    proxy: { 
     type: 'ajax', 
     url: 'info', 
     reader: { 
      type: 'json', 
      rootProperty: 'records' 
     } 
    } 
}); 

var fn = function getSelectedRow(gridView, rowIndex, colIndex, column, e,direction) { 
     var me = this; 
     var store = gridView.getStore(); 
     var record = store.getAt(rowIndex); 
     var inst = Ext.create('model.instance', { 
      name: record.get('name') 
     }); 
     inst.load({ 
      scope: this, 
      success: function(rec) { 
       console.log(rec); 
      } 
     }); 
} 

var store1 = Ext.create('Ext.data.Store', { 
    fields: ['name', 'surname'], 
    data: [{ 
     name: 'Rick', 
     surname: 'Donohoe' 
    }, { 
     name: 'Jane', 
     surname: 'Cat' 
    }] 
}); 
var grid = Ext.create('Ext.grid.Panel', { 
    columns: [{ 
     dataIndex: 'name' 
    }, { 
     dataIndex: 'surname' 
    }, { 
     xtype: 'actioncolumn', 
     text: 'Select', 
     icon: '/image', 
     handler: Ext.bind(fn, this) 
    }], 
    store: store1, 
    renderTo: Ext.getBody() 
}); 
+0

я попробовать, но получить эту ошибку в консоли: HTTP : //localhost/kds-rest/web/index.php/people/view/undefined? 404 (не найдено) –

+0

Отредактировано мое сообщение, еще раз проверьте пожалуйста. –

+0

все еще возвращает ту же ошибку –

Смежные вопросы