jeasyUI如何在combogrid中获取attr ID?

时间:2018-01-28 07:54:08

标签: javascript php jquery datagridviewcombobox jeasyui

$('#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');
    }
});

我如何获取ID 警报的属性名称($(this).attr(&#39; id&#39;); 应该是 mustGetID ,任何人请帮忙

2 个答案:

答案 0 :(得分:0)

尝试此$(row).attr('id),因为选择将返回该元素和元素的索引

答案 1 :(得分:0)

this指的是调用它的对象。这意味着this将引用您单击的行。换句话说,你无法轻易得到你想要的东西。如果唯一的目的是获取combogrid元素的id,我建议将元素的id存储在变量中,并将其保存在onSelect的范围内,以便您可以访问它。像,

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