设置标记可见与淘汰赛JS ko.utils.arrayFilter [英] Set marker visible with knockout JS ko.utils.arrayFilter
问题描述
你好,我正尝试创建一个应用程序,在敲除搜索完成时设置适当的标记。
基本上,应用程序是。
当某人搜索下面的列表时,过滤列表并仅使与地图上可见的过滤器列表关联的标记。
我创建了一个ko.utils.arrayFilter,我试图只设置item.marker.setVisible(true)
我的Github链接是 https://github.com/Aimpotis/map3
再次感谢你和对社区的尊重,它帮助我学到了很多东西。
解决方案你需要的是设置
if(!filter){
//这是新的
ko.utils.arrayForEach(self.listLoc(),function(item){
item.marker.setVisible(true);
});
返回self.listLoc();
} else {
return ko.utils.arrayFilter(self.listLoc(),function(item){
var result =(item.title.toLowerCase()。search(filter)> ; = 0)
item.marker.setVisible(result); //这是一个新行
返回结果;
});
}
注意:除非您支持特别旧的浏览器,否则您可以使用数组过滤器方法而不是Knockout的 arrayFilter
util和 .foreach
而不是 arrayForEach
。
Hello guys I am trying to create an app that sets the appropriate markers visible when a knockout search is being done.
Basically the app is. When someone does a search the list that is bellow it, filters the list and makes only the markers that are associated with the filter list visible on the map. I have created a ko.utils.arrayFilter and I am trying to set only the item.marker.setVisible(true)
My Github link is https://github.com/Aimpotis/map3
Thank you again and much respect to the community it is helping me learn a lot
All you need is to set the visibility of the marker to match whether it is found:
if (!filter) {
// this is new
ko.utils.arrayForEach(self.listLoc(), function (item) {
item.marker.setVisible(true);
});
return self.listLoc();
} else {
return ko.utils.arrayFilter(self.listLoc(), function(item) {
var result = (item.title.toLowerCase().search(filter) >= 0)
item.marker.setVisible(result); // this is a new line
return result;
});
}
Note: unless you're supporting particularly old browsers, you can use the Array filter method rather than Knockout's arrayFilter
util, and .foreach
instead of arrayForEach
.
这篇关于设置标记可见与淘汰赛JS ko.utils.arrayFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!