• 1.
    define(['ko', 'viewmodels/base'], function(ko) {
  • 2.
     
  • 3.
    var employee = {};
  • 4.
     
  • 5.
    employee.Model = function(data) {
  • 6.
    	this.id = data.id || 0;
  • 7.
    	this.name = ko.protectedObservable(data.name);
  • 8.
    }
  • 9.
     
  • 10.
    employee.ViewModel = function() {
  • 11.
    	var self = this;
  • 12.
     
  • 13.
    	// Inherit BaseViewModel
  • 14.
    	baseViewModel.call(self);
  • 15.
     
  • 16.
    	// Load Content
  • 17.
    	self.items =  ko.observableArray();
  • 18.
    	
  • 19.
    	self.load = function() {
  • 20.
    	    $.get("http://api/", function(data) {
  • 21.
    		var items = ko.utils.arrayMap(data.employees, function(item) {
  • 22.
    			return self.items.push(new employee.Model(item));
  • 23.
    		});
  • 24.
    	    });
  • 25.
    	}
  • 26.
     
  • 27.
    	// Add Employee
  • 28.
    	self.add = function(data) {
  • 29.
    	    // ...
  • 30.
    	}
  • 31.
     
  • 32.
    	// Update Employee
  • 33.
    	self.save = function(data) {
  • 34.
    	    // ...
  • 35.
    	}
  • 36.
     
  • 37.
    	// Delete Employee
  • 38.
    	self.delete = function(item) {
  • 39.
    	    // ...
  • 40.
    	}
  • 41.
    }
  • 42.
     
  • 43.
    return employee;
  • 44.
     
  • 45.
    });
define(['ko', 'viewmodels/base'], function(ko) { var employee = {}; employee.Model = function(data) { this.id = data.id || 0; this.name = ko.protectedObservable(data.name); } employee.ViewModel = function() { var self = this; // Inherit BaseViewModel baseViewModel.call(self); // Load Content self.items = ko.observableArray(); self.load = function() { $.get("http://api/", function(data) { var items = ko.utils.arrayMap(data.employees, function(item) { return self.items.push(new employee.Model(item)); }); }); } // Add Employee self.add = function(data) { // ... } // Update Employee self.save = function(data) { // ... } // Delete Employee self.delete = function(item) { // ... } } return employee; });

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter