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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:21:21+00:00 2026-06-03T09:21:21+00:00

I have an observable array binding to a dropdownlist. The dropdownlist is populated on

  • 0

I have an observable array binding to a dropdownlist. The dropdownlist is populated on page load via ASP.NET MVC Html Helpers, but since the observable array is set to [], it removes everything. Is there a way to not have it remove everything on page load or initial apply bindings.

  • 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-03T09:21:23+00:00Added an answer on June 3, 2026 at 9:21 am

    It sounds like you want to set the options from the observable array at a later time (from an AJAX call maybe?). Knockout doesn’t have any built-in way to do this. I see you have at least three options:

    1. The obvious way is to have your ASP.NET code fill out the observable array instead of the select list. Then Knockout will do the right thing and populate your drop-down list.

    2. Use a custom binding that wraps the options binding, but ignores empty arrays:

      ko.bindingHandlers.optionsNotBlank = {
          update: function (element, valueAccessor, allBindingsAccessor) {
              var value = ko.utils.unwrapObservable(valueAccessor());
              if (value.length)
                  ko.bindingHandlers.options.update(element, valueAccessor, allBindingAccessor);
          }
      };
      
    3. Set the options binding on the drop-down list dynamically. This is not a published feature, but does use an exported Knockout method. Instead of using the standard data-bind attribute, you’ll be using the ko.applyBindingsToNode method and passing it a binding object after you’ve filled in your observable array. You’ll need to be careful to only call ko.applyBindingsToNode once though.

      viewModel.myArrayOfItem(newValues);
      if (!boundDropDown) {
          ko.applyBindingsToNode(document.getElementById("mydropdown"), { options: viewModel.myArrayOfItems }, viewModel);
          boundDropDown = true;
      }
      

    Edit:

    Here’s a fourth option based on the comments using a “dirty” flag:

        ko.bindingHandlers.optionsNotBlank = {
            update: function (element, valueAccessor, allBindingsAccessor) {
                var value = ko.utils.unwrapObservable(valueAccessor()),
                    isDirty = element._isDirty;
                if (isDirty || value.length) {
                    element._isDirty = true;
                    ko.bindingHandlers.options.update(element, valueAccessor, allBindingAccessor);
                }
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have observable array with sites, which is shown via template. If I'll
I have a an array of observable collections and I want to display all
I have made a generic Observer interface and an Observable class, but can't compile
Hi (another Knockout question :-( , sorry) I have an observable array with five
I have a complex page that uses knockout to render the contents via templates.
If I have an observable array foos = [{ name: a }, { name:
I have an observable array that holds a list of people and a table
We have a large nested observable array mapped though templates to create a tree
I have the following issue: I have an observable array of objects in the
i have a an observable array in my model that is bind to just

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.