我最终使用jQuery PubSub、UI Layout 的访问器方法和 SlickGrid 的resizeCanvas()
方法来解决这个问题。它似乎工作得很好。
注意:我的项目已经在使用 pubsub,我使用RequireJS加载我的模块。
因此,在我的网格模块文件中,我订阅了一个方法来接收它所在窗格的新 innerHeight,它将它保存到一个局部变量中,然后调用我的resize();
函数:
$.subscribe("units/set_grid_height", function (new_height) {
grid_opts.height = new_height;
resize();
});
// ...
// grid = the jQuery element that represents the SlickGrid
// slick = the instantiated slickgrid
function resize() {
grid.css('height', grid_opts.height);
slick.resizeCanvas();
}
然后,在我的 init js 文件(其中定义了布局)中,我为初始状态和每次中心窗格更改时设置了正确的发布:
layout = $('body').layout({
center: {
onresize: function (name, el, state, opts, layout_name) {
$.publish("units/set_grid_height", [state.innerHeight]);
}
}
});
$.publish("units/set_grid_height", [layout.state.center.innerHeight]);
这似乎正是我想要的。我知道这不是一个通用的解决方案,但它看起来不像 SlickGrid 可以自己完成所有这些。