0

我有一个 observableArray,我通过它arrayFilter返回一个过滤集。但我目前只为 1 个 observable 做这件事。如何添加第二个 observable:

return ko.utils.arrayFilter(self.complaints(), function (complaint) {
    return complaint.RaisedBy == self.currentUser();
});

所以我还想根据我的对象的Code属性进行过滤:complaint

return ko.utils.arrayFilter(self.complaints(), function (complaint) {
    return complaint.Code == self.currentCode();
});

我怎样才能将它们两者结合起来?

4

2 回答 2

2

你有没有尝试过:

return ko.utils.arrayFilter(self.complaints(), function (complaint) {
    return complaint.Code == self.currentCode() && complaint.RaisedBy == self.currentUser();
});
于 2012-08-24T11:08:34.127 回答
0

像这样的东西应该工作:

self.myDependantObservable = ko.computed(function(){
   var currentUser = self.currentUser();
   var currentCode = self.currentCode();

   return result = ko.utils.arrayFilter(self.complaints(), function (complaint) {
     return (complaint.RaisedBy == currentUser && complaint.Code == currentCode);
   });

});
于 2012-08-24T11:09:36.840 回答