knockout.js - RequireJS Knockout Amd-Helper -


i'm struggling arranging code using requirejs , appreciate help.

i have dashboard.html gets bound 'dashboard' viewmodel in dashboard-init.js. dashboard viewmodel has list of panels shown list in dashboard.html.

after render completes, invoke gridlist function convert list dashboard.

please note works correctly if include these scripts in html using script src=... etc.

but when removed script tags , pushed these dependencies dashboard viewmodel, error:

uncaught error: unable process binding "foreach: function (){return { data:panels,afterrender:postrender} }" message: gridlist lib required 

what need satisfy gridlist lib requirement?

here page giving error (dashboard.html):

<html> <head>     <link rel="stylesheet" href="css/style.css" /> </head> <body>     <div class="grid-container">         <ul id="grid" class="grid" data-bind="foreach: { data: panels, afterrender: postrender }">             <li ...">                 ...             </li>                     </ul>     </div>     <script src="scripts/require.js"></script>     <script src="viewmodels/common-init.js"></script>     <script src="viewmodels/dashboard-init.js"></script>  </body> 

this common-init looks like:

requirejs.config({ baseurl: "../scripts", paths: {     "jquery": "jquery-2.0.3.min",     "jqueryui": "jquery-ui-1.11.4.min",     "knockout": "knockout-3.3.0",     "knockout-amd-helpers": "knockout-amd-helpers",     "text": "text" }, shim: {     'gridlist': ['jquery'],     'jquery.gridlist': ['jquery','gridlist'] } 

});

here dashboard-init

require(["knockout", "../viewmodels/modules/dashboard", "knockout-amd-helpers", "text"], function (ko, dashboard) {  ko.amdtemplateengine.defaultpath = "../templates";  ko.bindinghandlers.module.basedir = "modules";  ko.bindinghandlers.module.templateproperty = "embeddedtemplate";  settimeout(function () {     ko.applybindings(new dashboard()); }, 0); 

});

finally, here dashboard module:

define(["knockout", "jquery", "jqueryui", "gridlist", "jquery.gridlist"], function (ko) { return function () {     var self = this;      self.panels = [{...}, {...}];      self.postrender = function(elements, data) {         if (this.foreach[this.foreach.length - 1] === data) {             $('#grid').gridlist({                 rows: 3,                 widthheightratio: 264 / 294,                 heighttofontsizeratio: 0.25             });         }     } }; 

});

also, don't fact need refer #grid inside viewmodel not know better. advice help.

thanks

i haven't used gridlist working with, see have check window.gridlist throwing error seeing. in amd setting, not exposed on window. should check gridlist dependency there instead.

you can work around doing:

define(["knockout", "jquery", "gridlist", "jqueryui", "jquery.gridlist"], function (ko, $, gridlist) {         window.gridlist = gridlist;          // other code     }); 

as far accessing #grid element, access of elements parentnode instead or better consider using custom binding on parent element initializes gridlist.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -