javascript - Knockout.js textarea binding not updating after subscribe (item selected in combo box) -


i'm pretty new this, can't figure out i'm doing wrong... text-area not getting new value after subscribe occurs (item selected in combo-box) i'm getting data requests... can't figure out if i'm not doing in success part of 'subscribe' inside viewmodel or if wrong bindings... appreciated...

<div style="margin-top: 100px; width: 80%; margin-left: auto; margin-right: auto;">  <h2>workflows</h2>  <select data-bind="options: workflows, optionstext: 'name', value: workflow, optionscaption: 'choose workflow...'"> </select> <input data-bind="click: put" id="runworkflow" type="button" value="run workflow" /> <textarea data-bind="value: moo" type="text" style="background-color: beige; color: black; display: block; margin-top: 20px; height: 400px; width: 80%;"> </textarea> 

<script type="text/javascript">  var workflowviewmodel = function () {      self = this;     self.name = ko.observable("who");     self.moo = ko.observable("george");      var workflow =     {         name: self.name,         moo: self.moo     };      self.workflow = ko.observable();     self.workflows = ko.observablearray();      $(document).ready(function ()     {         $.ajax({             url: '@url.action("get", "workflow", new { httproute = "api" })',             cache: false,             type: 'get',             contenttype: 'application/json; charset=utf-8',             data: {},             success: function (data)             {                 self.workflows(data);             }         });     });      self.workflow.subscribe(function (workflow)     {          $.ajax({             url: '@url.action("get", "workflow", new { httproute = "api" })',             cache: false,             type: 'get',             contenttype: 'application/json; charset=utf-8',             data: { name: workflow.name },             success: function (data)             {                 self.moo = data.moo;                 self.name = data.name;             }         });     });  };  var workflowviewmodel = new workflowviewmodel(); ko.applybindings(workflowviewmodel); 

you're not setting value of observable correctly. change this:

self.moo = data.moo; self.name = data.name; 

to this:

self.moo(data.moo); self.name(data.name); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -