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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:16:23+00:00 2026-05-26T10:16:23+00:00

I am trying to populate Select using knockout data-bind option for a list of

  • 0

I am trying to populate “Select” using knockout data-bind option for a list of values and set one of the values as “selected” by default.

There are two server requests,

  1. Get the list of values (dataRepository.GetLifelines)
  2. Set one of the values as Selected from the list. (dataRepository.GetMockSelectedLifeline)

First requirement has been addressed. data-bind to a select is working fine with “Selected” value.

I am having issue with setting the default “Selected Value” in the list. Can someone please help me. method is this.selectValue. It is trying to set the selectedLifeline to the matching “Name”.

    function LifelineViewModel() {
    this.lifelines = ko.observableArray([{}]);
    this.selectedLifeline = ko.observable();

    this.updateData = function (data) {
        var boundUpdate = bind(function (value) {
            this.lifelines.push(value);
        }, this);

        $.each(data, function (index, item) {
            boundUpdate(item);
        });
        dataRepository.GetMockSelectedLifeline(bind(this.selectValue, this));
    }

    this.selectValue = function (data) {
        this.selectedLifeline = ko.utils.arrayFirst(this.lifelines, function (lifeline) {
            return lifeline.Name === data.Name;
        });
    }
}

LifelineViewModel.prototype.Init = function () {
    var boundUpdateData = bind(this.updateData, this);
    dataRepository.GetLifelines(boundUpdateData);
}

var bind = function (func, thisValue) {
    return function () {
        return func.apply(thisValue, arguments);
    }
}
  • 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-05-26T10:16:24+00:00Added an answer on May 26, 2026 at 10:16 am

    As selectedLifeline is an observable you are not setting its value correctly.

    Could you try this. Instead of:

    this.selectValue = function (data) { 
        this.selectedLifeline = ko.utils.arrayFirst(this.lifelines, function (lifeline) { 
            return lifeline.Name === data.Name; 
        }); 
    } 
    

    .. something like…

    this.selectValue = function (data) { 
        this.selectedLifeline(ko.utils.arrayFirst(this.lifelines, function (lifeline) { 
            return lifeline.Name === data.Name; 
        })); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP, I'm trying to populate an HTML list with data from two different
I am trying to populate an HTML select list using an array of customer
I'm trying to populate a list, and my question is how do you bind
I am trying to populate a dropdown select with an array using jQuery. Here
ok so I am trying to dynamically create a select list using javascript, basically
I am trying to populate a select box (cities related to a state) using
I am trying to populate the <s:select options using a struts action class. How
I am trying to populate a jqGrid search form using a SELECT element. In
I am trying to populate a chained State City select dropdowns. I am using
I'm trying to bind an onChange event of one FilteringSelect to populate another FilteringSelect

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.