Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockoutJS: cannot update the option value
    primarykey
    data
    text
    <p>i am working on a webpage that consists a JQuery item and a Knockout Item. </p> <p>basically the view has a select field and a sevond view that is being updated by the select value change. </p> <p>also i have a textbox search field with jquery autocomplete. </p> <p>What i want to do is when i press enter after on the search box, the javascript will update the ko.observable value and trigger the ther updates yet its not working. i've managed to trigger keypress but i cant update and trigger the update..</p> <p>Heres the code: </p> <pre><code> function Station(data){ var self = this; this.userId = ko.observable(data.userid); this.displayName = ko.observable(data.displayName); this.email = ko.observable(data.email); this.redirectURL = ko.computed(function(){ return "/someurl/somerequest?userId="+self.userId(); }); this.selectText = ko.computed(function(){ return self.displayName(); }) } function currentStation(index) { return self.stations()[index]; } function StationViewModel(){ var self = this; self.stations = ko.observableArray([]); $("#stationSelect").attr("disabled,true"); $.getJSON("@{someurl.getStationList()}",function(allData){ var mappedStations = $.map(allData,function(item) { return new Station(item); }); self.stations(mappedStations); $("#stationSelect").attr("disabled,false"); }); url = "/someurl/somerequest?userId="; this.selectedStation = ko.observable(); this.redirectToStation = function(){ var linkToSend = alert(self.selectedStation.redirectURL()); } &lt;!-- THIS IS THE CODE THAT HAS TO UPDATE THE FIELD BUT IT DOESN'T--&gt; this.getStation = function(event) { for(i = 0; i&lt;this.stations().length;i++) { if(this.stations()[i].userId()==$("#search").val()) { self.selectedStation = ko.observable(this.stations()[i]); //Am i doing it right? } } }; } &lt;!-- This is the code That handles the click event inside the textbox. its working --&gt; ko.bindingHandlers.executeOnEnter = { init: function (element, valueAccessor, allBindingsAccessor, viewModel) { var allBindings = allBindingsAccessor(); $(element).keypress(function (event) { var keyCode = (event.which ? event.which : event.keyCode); if (keyCode === 13) { allBindings.executeOnEnter.call(viewModel); return false; } return true; }); } }; ko.applyBindings(new StationViewModel()); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload