1

我是 javascript 的新手。我正在使用以下函数创建光滑网格,并根据日期操作 url 并获取数据。当我将此代码用于不同日期时,浏览器中的内存需求正在增加。我在这里做错了吗?

var createSlickGrid = function(data, key) {
    var options = ...;
    new Slick.grid($('#temp'), data, options);
}

getData = function(date) {
    url = <some function based on date>;
    $.getJSON(url, function(data) {
       createSlickGrid(data, key);
       data = null;
    });
}
4

2 回答 2

1

我认为您不想每次都创建一个新的 slickgrid,而是使用 slickgrid 包中的 slick.remotemodel.js。使用这个例子作为参考来帮助你: http: //mleibman.github.com/SlickGrid/examples/example6-ajax-loading.html

于 2013-01-24T15:55:28.997 回答
0

When you create the new Slickgrid, you are not clearing out the old, so they keep building until garbage collection eventually gets to it.

Aid your code by returning the instance of Slick.grid, so when you create a new one, if that is what you want, as @Drew was corrected, you could simply reload it, then you can dereference the original Slickgrid, or set it to NULL to allow the garbage collection to clean it up.

于 2013-01-24T18:27:06.793 回答