Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ext js 6将动态id从网格面板传递到模型_Javascript_Extjs_Parameters_Model - Fatal编程技术网

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

Javascript ext js 6将动态id从网格面板传递到模型,javascript,extjs,parameters,model,Javascript,Extjs,Parameters,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

如何将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(); 
编辑:如何动态加载模型:fiddle:


我尝试了,但在控制台中出现了以下错误:?404(未找到)编辑了我的帖子,请再次检查。您确定rec.get('id')返回的处理程序中未定义吗?“id”似乎未定义。是的,我尝试将相同的代码从模型放到存储区,并将其调用到网格面板,没有错误,但它在网格中没有显示任何内容。如果我想将id传递到存储区如何?可以像模型一样使用相同的代码吗?
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()
});