从其实例中获取slickgrid的id

时间:2014-08-07 00:00:11

标签: javascript slickgrid

我希望使用实例变量获取slickgrid实例的id(任何表示唯一实例的值都可以。)

我发现最好的是解析dom元素中的uid:

var sg = new Slick.Grid(...)
var classes = pg.mainGrid.getCanvasNode().parentNode.parentNode.classList
for (var i=i, len=classes.length; i<len; i++) {
  if (classes[i].contains('slickgrid')){
    var id = classes[i]
    break;
  }
}

这显然是愚蠢的。有人找到了更好的方法吗?

1 个答案:

答案 0 :(得分:0)

我认为最好的答案可能是将方法添加到SlickGrid。这是提交:

https://github.com/SimpleAsCouldBe/SlickGrid/commit/bc1342c25a81a7adbe6d52a9ece79ad716307a07

    +    // A simple way to expose the uid to consumers, who might care which slickgrid instance they're dealing with.
    +    function getId() {
    +      return uid;
    +    }
    ...
    +    "getId": getId,