Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockout mapping plugin not creating observable properties
    primarykey
    data
    text
    <p>I have a question regarding the use of the knockout mapping plugin.</p> <p>I'm fetching a simple array from the server and convert it into javascript objects using the mapping plugin. Since I want the properties on the items to be observable I'm supplying the pugin with a custom mapping for the create callback.</p> <pre><code> var meeting = function (id, titel, description) { var self = this; self.Id = id; self.Titel = ko.observable(titel); self.Description = ko.observable(description); self.Test = ko.computed(function () { return self.Description(); }); return self; } var mapping = { create: function (json) { return new meeting(json.data.Id, json.data.Titel, json.data.Description); } } </code></pre> <p>When I call the ko.mapping.fromJS(myFetchedData) I see (with debugger attached) the create-function being called for every item in my array. Everything is bound to the HTML controls fine. I see a li item appearing for every item in the array.</p> <pre><code>&lt;ul id="meetings" data-bind=" foreach: meetings"&gt; &lt;li class="ui-widget-content ui-corner-all"&gt; &lt;h1 data-bind="text: Titel" class="ui-widget-header"&gt;&lt;/h1&gt; &lt;div&gt; &lt;input type="text" data-bind="text: $data.Description || 'Omschrijving?'"&gt;&lt;/input&gt;, &lt;/div&gt; &lt;div&gt; &lt;input type="text" data-bind="text: $data.Test || 'Omschrijving?'"&gt;&lt;/input&gt;, &lt;/div&gt; &lt;a href="#" data-bind="click: $root.updateMeeting" &gt;Update&lt;/a&gt; &lt;a href="#" data-bind="click: $root.removeMeeting" &gt;Remove&lt;/a&gt;&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>However: the Description property does not seem to be Observable. Changing the value does not result in an updated value of the Test-computed property.</p> <p>Am I missing something here?</p> <p>Any help would be appreciated.</p> <p>Full sample code can be found here: <a href="http://jsfiddle.net/dtiemstra/wRg88/" rel="nofollow">http://jsfiddle.net/dtiemstra/wRg88/</a></p>
    singulars
    1. This table or related slice is empty.
    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