Skip to content

Instantly share code, notes, and snippets.

@valerysntx
Last active August 29, 2015 14:10

Revisions

  1. @rshackleton rshackleton created this gist Aug 19, 2014.
    38 changes: 38 additions & 0 deletions ko-module.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    define(['jquery', 'knockout', 'knockout.mapping', 'knockout.validation'],
    function ($, ko) {
    /** The module. */
    var self = {};

    /** The knockout view model. */
    self.viewModel = {};

    /** The knockout container. */
    self.container = null;

    /** Initialise the module. */
    self.initialise = function (container) {
    self.container = container;

    // Call API end point.
    $.getJSON('/API/End/Point',
    function (json) {
    self.viewModel = ko.mapping.fromJS(json);

    extendViewModel();

    var context = ko.contextFor(self.container);

    if (context === undefined)
    ko.applyBindings(self.viewModel, self.container);
    }
    );
    };

    /** Extend the view model. */
    var extendViewModel = function () {

    };

    return self;
    }
    );