我如何获得 w2ui 网格单元格值?

how do i get a w2ui grid cell value?

我想获取 w2ui 网格的 "id" 值。记录来自数据库

columns: [
{ field: 'id', caption: 'ID', size: '50px' }, { field: 'name', caption: 'Name', size: '300px'},]

我的函数

onDblClick: function (event) {

           var grid = this;
           event.onComplete = function () {
           var sel = grid.getSelection();
           console.log('my id value ' + sel.id);
      }

但什么也没有出现。我做错了吗?

grid.getSelection() returns 一组选定的记录,请参阅 the documentation

您应该按如下方式更改代码:

$(function() {
  $('#grid').w2grid({
    name: 'grid',
    columns: [
      { field: 'id', caption: 'ID', size: '50px' }, 
      { field: 'name', caption: 'Name', size: '300px' }
    ],
    records: [
      { recid: 1, id: '1', name: 'Name 1' },
      { recid: 2, id: '2', name: 'Name 2' } 
    ],
    onDblClick: function(event) {
      var grid = this;
      event.onComplete = function() {
        var sel_rec_ids = grid.getSelection();
        if (sel_rec_ids.length) {
          var sel_record = grid.get(sel_rec_ids[0]);
          console.log('selected ID:', sel_record.id, '/ selected Name:', sel_record.name);
        } else {
          console.log("Nothing selected!");
        }
      }
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.js"></script>
<link href="https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.css" rel="stylesheet" />

<div id="grid" style="width: 100%; height: 150px;"></div>


另外让我引用一些其他人在 2013 年对您的一个问题发表的评论:

I see you've not accepted any answer to your questions. That kinda defeats the goal of Stack Overflow. It would be great if you could review all the questions you've asked, accept correct answers and give feedback on proposed solutions that don't work