How Can I Generate Client-side View Models For Knockout In An Asp.net Mvc Project?
I am currently working on an ASP.NET MVC solution and have recently introduced both Knockout (an MVVM JS library) and Wijmo (a set of jQuery UI widgets). With the introduction of K
Solution 1:
According to their tutorials it's just a simple .map
function
If this is the ViewModel
function Task(data) {
this.title = ko.observable(data.title);
this.isDone = ko.observable(data.isDone);
}
And this function get's the data from the server, it uses the .map
function to inject the server data right into the VM
// Datavar self = this;
self.tasks = ko.observableArray([]);
// Load initial state from server, convert it to Task instances, then populate self.tasks
$.getJSON("/tasks", function(allData) {
var mappedTasks = $.map(allData, function(item) {
returnnewTask(item)
});
self.tasks(mappedTasks);
});
For ko mapping http://knockoutjs.com/documentation/plugins-mapping.html
For auto-bind here's an example
https://groups.google.com/forum/#!msg/knockoutjs/IJTx37UXQVw/UTrWdEK1C-oJ
Solution 2:
Try this pluggin for visual studio http://visualstudiogallery.msdn.microsoft.com/32c15a80-1c54-4e96-a83f-7cd57573a5d2
Post a Comment for "How Can I Generate Client-side View Models For Knockout In An Asp.net Mvc Project?"