Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using knockout.simpleGrid.3.0.js with Require.js

I am using require.js with knockout on a website and would like to use the simpleGrid example from this link http://knockoutjs.com/examples/grid.html however I cannot include kncokout.simpleGrid.3.0.js with Require.

I have tried wrapping the plugin with

define(['jQuery', 'knockout'], // Require knockout
    function($, ko) {

   });

This does not work it seems the problem occurs with the templates.

Any help appreciated

like image 677
danny Avatar asked Mar 13 '14 09:03

danny


1 Answers

In your require config, you should create a path to the simpleGrid library and use the shim to tell it that it depends on Knockout so that your libraries are loaded in the correct order. Here's an example:

var require = {
    paths: {
        'jquery': 'lib/vendor/jquery-2.0.3',
        'ko': 'lib/vendor/knockout-3.0.0',
        'koSimpleGrid': 'lib/vendor/knockout.simpleGrid.3.0'
    },
    shim: {
        'koSimpleGrid': {
            deps: ['ko']
        },
    }
};

And then you could copy paste the view model code from the example inside of a define like this:

define(['jquery', 'ko', 'koSimpleGrid'], function ($, ko) {
    // VIEW MODEL GOES HERE
});
like image 88
Simon LeVasseur Avatar answered Oct 14 '22 12:10

Simon LeVasseur