knockout.js - Access viewmodel in knockout mapping plugin -
i using knockout mapping plugin add computed property item in observable array. however, computed property relies on different property in viewmodel. how access viewmodel property when creating observable during mapping? please note cannot use options.parent, because property further in viewmodel. i unable change viewmodel, because generated server side. edit: here's jsfiddle shows issue. line commented out need working. http://jsfiddle.net/g46mt/2/ this have now, throwing error: var mapping = { 'collection': { create: function(options) { var model = ko.mapping.fromjs(options.data); model.total = ko.computed(function() { var result = this.price() * viewmodel.count(); // :( return result; }, model); return model; } } }; var json = { ... large json object ... }; var viewmodel = ko.mapping.fromjs(json, mapping); one possible solution use {defer...