javascriptphpjquerydatagridviewcomboboxjquery-easyui

jeasyUI how to get attr ID in combogrid?


$('#mustGetID').combogrid({
    panelWidth:500,
    panelHeight:250,
    url: '<?= $url; ?>get_item.php',
    queryParams: {
      id_item: row.id_item
    },
    idField:'id_item',
    textField:'name_item',
    mode:'remote',
    fitColumns:true,
    nowrap: false,
    columns:[[
      {field:'id_item',title:'id_item',width:100},
      {field:'name_item',title:'name_item',width:200}
    ]]
    ,onSelect: function(index,row){
      alert($(this).attr('id');
    }
});

how i get attribute name of id alert($(this).attr('id'); should be get mustGetID ,, anyone please help


Solution

  • this refers to the object that invoked it. That mean this will refer to the row on which you clicked. So in other words, you cannot get what you want easily. If the sole purpose is to get the id of combogrid element, what I would recommend is store the id of element in a variable and keep it in scope of onSelect so that you can access it. Something like,

    var $el = 'mustGetID';
    
    $('#' + $el).combogrid({
    panelWidth:500,
    panelHeight:250,
    url: '<?= $url; ?>get_item.php',
    queryParams: {
    id_item: row.id_item
    },
    idField:'id_item',
    textField:'name_item',
    mode:'remote',
    fitColumns:true,
    nowrap: false,
    columns:[[
    
         {field:'id_item',title:'id_item',width:100},
         {field:'name_item',title:'name_item',width:200}
    ]]
    ,onSelect: function(index,row){
    alert($el);
    }
    });