Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8348755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:47:10+00:00 2026-06-09T07:47:10+00:00

Lets say I have an viewmodel with an observablearray of products that has an

  • 0

Lets say I have an viewmodel with an observablearray of products that has an array of categories (Id, Name) on the Product Object. I then also have an observablearray of filters which are just categories. Is there a way that i can find all the products that have all the categories in the filters observable array. So, I need to return all products that have all the categories in the filters array and not just one filter, but the product must contain all the filters. Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:47:12+00:00Added an answer on June 9, 2026 at 7:47 am

    I think it should looks like that:

            function Product(id, name) {
                this.id = id;
                this.name = name;
                this.categories = [];
            }
    
            function ProductCategory(name) {
                this.name = name;
            }
    
            function ViewModel() {
                this.products = ko.observableArray();
                this.filters = ko.observableArray();
                var self = this;
    
                //dummy data
                self.init = function () {
                    var c1 = new ProductCategory('Cat1');
                    var c2 = new ProductCategory('Cat2');
                    var c3 = new ProductCategory('Cat3');
                    var c4 = new ProductCategory('Cat4');
    
                    var p1 = new Product(1, 'Prod 1');
                    p1.categories = [c1, c2];
    
                    var p2 = new Product(2, 'Prod 2');
                    p2.categories = [c1, c3, c4];
    
                    var p3 = new Product(3, 'Prod 3');
                    p3.categories = [c3, c4];
    
                    var p4 = new Product(4, 'Prod 4');
                    p4.categories = [c1, c2, c4];
    
                    self.products([p1, p2, p3, p4]);
                    self.filters([c1, c3, c4]);
                };
    
                self.init();
    
                //filtered products will be recalculated on products or filters array change
                self.filteredProducts = ko.computed(function () {
                    var filteredProducts = [];
                    ko.utils.arrayForEach(self.products(), function (product) {
                        var notInFilter = false;
    
                        for (var i = 0; i < product.categories.length; i++) {
                            var category = product.categories[i];
    
                            if (self.filters().indexOf(category) < 0) {
                                notInFilter = true;
                                break;
                            }
                        }
    
                        if (!notInFilter) {
                            filteredProducts.push(product);
                        }
                    });
    
                    return filteredProducts;
                });
            }
    

    Fiddle with code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a boolean property in my ViewModel, named lets say IsNotSupported that is
In my application, I have a model object that contains a collection lets say
Lets say I have a class A that is fairly simple like this -
lets say i have one array a = numpy.arange(8*6*3).reshape((8, 6, 3)) #and another: l
Is anything really wrong with a ViewModel opening additonal dialogues? Lets say I have
The situation is as follows: I have a ViewModel that has a property that's
Lets say I have a viewmodel like this var viewModel = { Dtos: [{
Let's just say I have A ViewModel that is made up of 3 other
Let's say I have a theoretical MVC framework that uses a ViewData object to
Lets say I have the following entities that map to database tables (every matching

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.