knockout.js - How to use knockout mapping plugin with Durandal? -
i'm new in durandal, , wanted rewrite existing knockout project using framework. in old project i'm using knockout mapping plugin , have problem it. work durandal sample project base. here piece of code:
define(['durandal/app', 'durandal/system', 'knockout'], function (app, system, ko) { var clients = ko.observablearray([]); return { clients: clients, activate: function(data) { var self = this; ko.mapping.fromjs(getdata(), {}, self.clients); } }; };
the error is:
uncaught typeerror: cannot call method 'fromjs' of undefined
indeed, undefined, should add , make working?
thanks.
you should add mapping plugin in define
otherwise not going load it.
define(['durandal/app', 'durandal/system', 'knockout', 'knockout-mapping'], function (app, system, ko) {
make sure able load script in requirejs configuration.
i suggest load knockout , mapping plugin in main.js
so don't need keep "requiring" them in viewmodels. can bundle them separately , not part of loader.
Comments
Post a Comment