繁体   English   中英

ext js 6将动态ID从网格面板传递到模型

[英]ext js 6 pass dynamic id from grid panel to model

如何将ID从gridpanel传递给模型? 这是我的网格面板代码:

{
     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',
});

您如何使用该模型? 如果您每次都创建或使用它,则可以尝试以下操作:

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(); 

编辑:如何动态加载模型:小提琴: 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()
}); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM