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 8290087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:41:42+00:00 2026-06-08T12:41:42+00:00

I have a Customer model like so (simplified): public int CustomerAcc { get; set;

  • 0

I have a Customer model like so (simplified):

public int CustomerAcc { get; set; }
public string Name { get; set; }
public int Blocked { get; set; }

Blocked has 3 possible values: 0, 1, 2. 0 means okay, 1 means customer is warned, 2 means customer is blocked.

I then have a knockout viewModel like so:

function SearchCustomerViewModel() {
    var self = this;
    self.custTerm = ko.observable('');
    self.customers = ko.observableArray([]);
    self.excludeClosedAccs = ko.observable(true);

    self.search = function () {
        $.ajax({
            url: "/api/SearchCustomers",
            data: { id: self.custTerm },
            type: "GET",
            success: function (data) {
                self.customers(data);
            }
        });
    }
}

$(document).ready(function () {
    var viewModel = new SearchCustomerViewModel();
    ko.applyBindings(viewModel);
    $("#btnSearch").click({ handler: viewModel.search });
});

This provides a simple search api which searches my customer repository. I have a property called excludeClosedAccs which I have set as true by default, which I would like to exclude any accounts in my view which have a Blocked equal to 2. This is a checkbox on my view, which when unticked, will include them in my results. Here is my View:

<div id="body">
    <h1>Customer Search</h1>

    <div>
        Search:<input type="text" data-bind="value: custTerm" />

        <input type="button" id='btnSearch' title="Search" value="Search" />
    </div>

    <div data-bind="visible: customers().length > 0">
        <span data-bind="text: customers().length"></span>
        customers found.
        <label>Exclude Closed Accounts: <input data-bind="checked: excludeClosedAccs" type="checkbox"/></label>
    </div>

    <div id="results-container" data-bind="template: { name: 'customer-results', foreach: customers }"></div>

</div>

<script type="text/html" id="customer-results">
    <div>
        <h6 data-bind="text: CustomerAcc"></h6>
        <p>Company Name: <span data-bind="text: Name"></span></p>
        <!-- ko if: Blocked > 0 -->
        <p>Blocked: <span data-bind="text: Blocked"></span></p>
        <!-- /ko -->
    </div>
</script>

Is it possible to apply a filter on my self.customers array to do what I wish or do I have to make a seperate request, one to exclude blocked accounts and one which includes them?

  • 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-08T12:41:44+00:00Added an answer on June 8, 2026 at 12:41 pm

    You want to use a computed method in your view model that returns either the full set if excludeClosedAccs is false or filter the array based on criteria you suggested like so:

    function SearchCustomerViewModel() {
    
        // properties
        var self = this;
        self.custTerm = ko.observable('');
        self.customers = ko.observableArray([]);
        self.excludeClosedAccs = ko.observable(true);
        self.customersToShow = ko.computed(function () {
            if (!self.excludeClosedAccs()) {
                return self.customers();
            }
            return ko.utils.arrayFilter(self.customers(), function (customer) {
                return customer.Blocked == 0 || customer.Blocked == 1;
            });
        });
    
        // methods
        self.search = function () {
            $.ajax({
                url: "/api/SearchCustomers",
                data: { id: self.custTerm },
                type: "GET",
                success: function (data) {
                    self.customers(data);
                }
            });
        }
    }
    
    $(document).ready(function () {
        var viewModel = new SearchCustomerViewModel();
        ko.applyBindings(viewModel);
        $("#btnSearch").click({ handler: viewModel.search });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Customer model, which has a lot of has_many relations, e.g. to
I have these 3 models in models.py class Customer(models.Model): name = models.CharField(max_length=50) .... class
I have some jQuery that looks like this: $.ajax({ type: POST, url: /Customer/CancelSubscription/<%= Model.Customer.Id
I have some model classes like Customer , Product , etc. in my project
I have the dropdown list like this <?php echo $form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array(
I have a model called Customer in google app engine with python: class Customer(db.Model):
I have two models: class Customer(models.Model): (...) class CustomerMemo(models.Model): (...) customer = models.ForeignKey(Customer) text
I have an Entity Framework data model. Part of the model is a Customer
I have Customer, Event and Address objects in my data model. Both Customer and
Is it possible for a model to belong_to, two models and have a nested

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.