2015-03-03 106 views
1

我正在使用AirBnb的infinity.js插件在我的应用程序中生成无限列表。infinity.js的最佳做法

我在创建关注页面时首次生成列表。 但是然后列表必须根据过滤复选框和选择按钮进行更新。 所以我必须重新生成列表。 鉴于我的清单new infinity.ListView($el);的创建是在函数resetModelsListView中,如果每次我想要更新列表时都会重新启动resetModelsListView,它会创建一个新的列表视图。如何管理这个请?

function resetModelsListView(prodata, firsttime, funfeatureOn, specificBrand, specificPro) { 
... 

//create listview 
var $el = $('#modelsListview'); 
var listView = new infinity.ListView($el); 

//add new content: 
var $newContent = $(optionsmodel); //optionsmodel is a list of <li>s 
listView.append($newContent); 

} 

回答

0

我不知道,如果这是很好的做法,但现在我这样做:

function resetModelsListView(prodata, firsttime, funfeatureOn, specificBrand, specificPro) { 
... 
//USING INFINITY.JS: 

//clear previous list 
if (typeof listView !== 'undefined') { 
    listView.remove(); 
    listView.cleanup(); 
} 

//reinit the list 
var $el = $('#modelsListview'); 
listView = new infinity.ListView($el); 

//adding new content: 
var $newContent = $(optionsmodel); 
listView.append($newContent); 
} 
+0

这是类似于我在做什么。我只是检查'typeof listView ==='object'',我相信调用'remove()'也会清理干净,所以使用两者都是多余的。 – andrewtweber 2015-10-03 05:06:14