Knockout Select Data Binding


Chris

I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't appear. Only the first drop-down list will be displayed in the page with all the correct data. However, the second one that should have appeared with all the room names did not appear. However, when I remove the first, the second works. I'm obviously missing something here, what would that be?

Here is my HTML code:

<div align = "center">
    <select data-bind="options: employees, 
        optionsText: 'FullName', 
        value: Id, 
        optionsCaption: 'Select employee to login'"class = "container">
    </select>
</div>  

<div align = "center">
    <select data-bind="options: meetingRooms, 
        optionsText: 'Location', 
        value: Id, 
        optionsCaption: 'Choose room to book'" class = "container">
     </select>
</div>  

Here is the java script code:

function BookingSystemViewModel() {
    var self = this;
    self.employees = ko.observableArray();
    self.meetingRooms = ko.observableArray();

    $.get( "/WebApi/API/Employees", function(data) {
        self.employees(data);
    });

     $.get( "/WebApi/API/MeetingRooms", function(data) {
        self.meetingRooms(data);
    });
Jonas 89
<div align = "center">
    <select data-bind="options: employees, 
        optionsText: 'FullName', 
        value: Id, 
        optionsCaption: 'Select employee to login'"class = "container">
    </select>
</div>  

<div align = "center">
    <select data-bind="options: meetingRooms, 
        optionsText: 'Location', 
        value: Id, 
        optionsCaption: 'Choose room to book'" class = "container">
     </select>
</div>  

You are saying valueit should be written to an observable name Idthat is not present in the view model . Maybe you're looking for optionsValuewhich property to use to define the value to be used as the selected object.

Related


Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout Select Data Binding

Chris I'm new to knockout and have a question about using data binding and "options" binding. I would like to have two dropdown lists with data from the database. I can get the first one to work, but even with the same implementation, the second one doesn't ap

Knockout JS - Binding select list to data object

Charlie Pope objective I wish to create a claim form. The claim form must support the following: Add (create) claim line Store (read) all claim lines Edit (update) claim line Delete (destroy) claim lines Display a variable number of fields based on user select

Knockout JS - Binding select list to data object

Charlie Pope objective I wish to create a claim form. The claim form must support the following: Add (create) claim line Store (read) all claim lines Edit (update) claim line Delete (destroy) claim lines Display a variable number of fields based on user select

Knockout data binding in function

BK52 Hi, I've tried a few things but I can't do that. HTML <div data-bind="dxTextBox: { value:my_var }"></div> JS var viewModel = { my_var: ko.observable(''), StartScan:function() { mytimer = setInterval(this.DataBind, 1000); }, DataB

Cleaner data binding in knockout?

Joe Scotto I'm new to using Knockout and am doing a very basic implementation to change colors in an observable way. Is there a cleaner way to write the following code? <div class="selected" data-bind="style: { background: fullHexCode(mainScreenNavigationSelec

Ajax data binding with Knockout Js

Kitty Sarvaj I am using knockout js and I am finding it difficult to bind data in ajax get method, I have created model, viewModel and ajax function, I have ajax method in the same js file where I am creating viewModel on page load ajax and try to bind my html

Ajax data binding with Knockout Js

Kitty Sarvaj I am using knockout js and I am finding it difficult to bind data in ajax get method, I have created model, viewModel and ajax function, I have ajax method in the same js file where I am creating viewModel on page load ajax and try to bind my html

Knockout Data Binding Browser Tool

Purvi How to trigger data bound properties from browser tools? In the example below, how can I set showDiv to true or false via browser tools? <div data-bind="visible:showDiv">Text</div> does not exist Just as you explicitly set a value in code, you can s

Combining Conditional Knockout and Data Binding

james Hi I'm wondering if knockout/databinding can conditionally add a class to an element if the condition is met Now I have something like <!-- ko if: ($index() % 2 != 0) --> <div class="col-md-5 pull-left" style="margin: 0px 5px 10px 5px; min-height

Knockout data binding for input types?

Eve Can you databind the type of the input control? Something like this: I believe I can just use and surround a few controls so I can use a different input control for each type if necessary. But I thought I'd check if there is a way to bind the type and chan

Knockout Data Binding Browser Tool

Purvi How to trigger data bound properties from browser tools? In the example below, how can I set showDiv to true or false via browser tools? <div data-bind="visible:showDiv">Text</div> does not exist Just as you explicitly set a value in code, you can s

How to handle data binding, knockout

Kagdas Aslan I have a client who is a member of a website. He has to fill out a form very frequently every time. That's why he asked me to develop an app for him that automates the process. When I do it with the webBrowser control, I can log in, but after that

Combining Conditional Knockout and Data Binding

james Hi I'm wondering if knockout/databinding can conditionally add a class to an element if the condition is met Now I have something like <!-- ko if: ($index() % 2 != 0) --> <div class="col-md-5 pull-left" style="margin: 0px 5px 10px 5px; min-height

Knockout data binding for input types?

Eve Can you databind the type of the input control? Something like this: I believe I can just use and surround a few controls so I can use a different input control for each type if necessary. But I thought I'd check if there is a way to bind the type and chan

Knockout binding not updating with foreach select option

Yono I have two options, the second option depends on the first option. Both select boxes need to have a class attached, so I can't use the options property. The only way I've found to do this is to use the foreach method. I need to keep track of two selected

Knockout binding not updating with foreach select option

Yono I have two options, the second option depends on the first option. Both select boxes need to have a class attached, so I can't use the options property. The only way I've found to do this is to use the foreach method. I need to keep track of two selected

Datatable data binding using knockout table

Gudia I want to render data into a table using datatable knockout js bindings. I am using the link and code below to render data into a table. http://datatables.net/dev/knockout/ The only changes I've made in the example above is that when rendering the age da

Using knockout data binding on nested uls

Shugo I am trying to use foreach data binding on a button. Because of the underlying split button, the button I'm trying to generate for each record has its own list of options. The problem is that the inner ul cannot access the correct item of the binding. I