gpt4 book ai didi

javascript - knockout js : ko. utils.arrayFilter 无法正常工作

转载 作者:行者123 更新时间:2023-12-03 06:10:01 25 4
gpt4 key购买 nike

所以我最近使用 knockout.js 将我想要的过滤系统插入到我的项目中。我将以下代码插入到我的项目中。

self.pointsFilter = ko.computed(function(){
return ko.utils.arrayFilter(self.pointsList(), function(pointItem){
return pointItem.done = true;
})
});

这是我之前的现有代码:

var point = function(obj){
var self = this;

this.name = obj.name;
this.street = obj.street;
this.city = obj.city;
this.state = obj.stat;
this.zip = obj.zip;
this.food = ko.observable(obj.food);
this.lat = ko.observable(obj.lat);
this.lng = ko.observable(obj.lng);
this.map = map;

this.fullAddress = function(){
return self.street + self.city + "</br>" + self.state + self.zip;
};

this.formattedAddress = function(){
var currentStreet = self.street + self.city + self.state + self.zip;
var newAddress = currentStreet.replace(/ /g, '+');
return newAddress;
};

this.formattedName = function(){
var newName = self.name.replace(/ /g, '');
return newName;
}

}

var viewModel = function(){
var self = this;
var marker;

this.pointsList = ko.observableArray([]);

points.forEach(function(pointItem){
self.pointsList.push(new point(pointItem));
});

self.pointsList().forEach(function(pointItem){

console.log(pointItem.formattedName());
console.log(pointItem.formattedAddress());

pointItem.marker = marker;

marker = new google.maps.Marker({
position: new google.maps.LatLng(pointItem.lat(), pointItem.lng()),
map: map,
animation: google.maps.Animation.DROP,
});

google.maps.event.addListener(marker, 'click', function(){
if(infowindow.marker != marker){
marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png'),
infowindow.open(map, this);
infowindow.setContent('<div><h1>' + pointItem.name +
'</h1><h2>' + pointItem.fullAddress() +
'</h2><img src=' + streetViewRequest +
'><div id="instafeed">' + '</div</div>' + instafeedRequest());
}
});

});

self.pointsFilter = ko.computed(function(){
return ko.utils.arrayFilter(self.pointsList(), function(pointItem){
return pointItem.done = true;
})
})

}

如果您想要填写 github 存储库,您可以在这里找到它 current github repository

最佳答案

您需要在过滤器的 return 语句中使用 Boolean 结果,以仅返回 did 值为 true 的内容。您的单个 equals 正在执行赋值而不是 bool 比较。

换句话说,您需要一个 double (或非强制值的三倍等于),如下所示:

return pointItem.done == true;

关于javascript - knockout js : ko. utils.arrayFilter 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39360448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com