knockout.js - knockout mapping with computed fields -


i'm getting data wcf service,and map, , bind data dom object :

var payinyvm = {};      $.getjson('/service/paidservice.svc/paidlist', function (data) {         var tmp = json.stringify(data.d);          payinyvm.model = ko.mapping.fromjson(tmp);         ko.applybindings(payinyvm);     });  

the result shown excepted on dom bind model. couldn't find out how add computed observable let's data returning people firstname , lastname, how can make computed observable fullname fn + ' ' + ln.

here's working copy of fiddle, had make lot of assumptions fiddle wasn't correct javascript , seemed quite confused , didn't reference knockout

var paidpeople = function(data) {     var self = this;     ko.mapping.fromjs(data, {}, this);     this.fullname = ko.computed(function () {                     return self.name() + " : ";                 }); }  var payinyvm = function (data) {                 var self = this;                  ko.mapping.fromjs(data, {                     'model' : {                         create: function(options) {                             return new paidpeople(options.data);                     }                                           }                 }, self);                             };  var data = {model:[{__type: "paidpeople:#model", amount:110, attendee:1, name:'john'}]};  ko.applybindings(new payinyvm(data)); ​ 

and fiddle works : http://jsfiddle.net/qeuhd/


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -