Thursday, 15 January 2015

jquery - Knockout not loading costom Bindings on $.getScript -



jquery - Knockout not loading costom Bindings on $.getScript -

i'm running main.js, , executing $.getscript(app.js) within main.js. knockout.js running, viewmodel comes app.js.

when seek insert custom bindings app.js, won't loaded knockout. viewmodel within same file works fine. when drop them end of main.js, loaded , available knockout.js

bindings defined follows:

ko.bindinghandlers.yourbindingname

this app.js:

var _dragged; ko.bindinghandlers.drag = { init: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var dragelement = $(element); var dragoptions = { helper: 'clone', revert: false, start: function () { _dragged = valueaccessor().value; }, cursor: 'default' }; dragelement.draggable(dragoptions).disableselection(); alert('init'); } }; ko.bindinghandlers.drop = { init: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var dropelement = $(element); var dropoptions = { drop: function (event, ui) { valueaccessor().value(_dragged); } }; dropelement.droppable(dropoptions); alert('init'); } }; ko.bindinghandlers.sortable = { init: function (element, valueaccessor) { // cached vars sorting events var startindex = -1, koarray = valueaccessor(); var sortablesetup = { // cache item index when dragging starts start: function (event, ui) { startindex = ui.item.index(); }, // capture item index @ end of dragging // move item stop: function (event, ui) { // new location item index var newindex = ui.item.index(); if (startindex > -1) { // item moved var item = koarray()[startindex]; // remove item koarray.remove(item); // insert item in list koarray.splice(newindex, 0, item); // ko rebinds array alter remove duplicate item ui.item.remove(); } } }; // bind $(element).sortable(sortablesetup); } }; function lanesmodel(lanes) { var self = this; this.lanes = ko.observablearray(lanes); this.observablelanes = ko.computed(function () { //for (var = 0; < self.lanes.length; i++) { // self.lanes()[i].childs = new ko.observablearray(lanes[i].childs); //} //self.lanes().childs = ko.observablearray(); //ko.observablearray(lanes.childs); }, this); }

this how load app.js main.js:

$.when(parselanes()).done(function(o1) { //alert(o1); //!!debug $.when($.getscript("./scripts/app_lanes.js"), $.getscript("http://code.jquery.com/ui/1.10.0/jquery-ui.js")) .done(function() { var vm = new lanesmodel(uniquelanes); ko.applybindings(vm); }); });

can help me?

this markup working, 1 used amd (requirejs):

(function () { var _dragged; ko.bindinghandlers.drag = { init: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var dragelement = $(element); var dragoptions = { helper: 'clone', revert: false, start: function () { _dragged = valueaccessor().value; }, cursor: 'default' }; dragelement.draggable(dragoptions).disableselection(); alert('init'); } }; ko.bindinghandlers.drop = { init: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var dropelement = $(element); var dropoptions = { drop: function (event, ui) { valueaccessor().value(_dragged); } }; dropelement.droppable(dropoptions); alert('init'); } }; ko.bindinghandlers.sortable = { init: function (element, valueaccessor) { // cached vars sorting events var startindex = -1, koarray = valueaccessor(); var sortablesetup = { // cache item index when dragging starts start: function (event, ui) { startindex = ui.item.index(); }, // capture item index @ end of dragging // move item stop: function (event, ui) { // new location item index var newindex = ui.item.index(); if (startindex > -1) { // item moved var item = koarray()[startindex]; // remove item koarray.remove(item); // insert item in list koarray.splice(newindex, 0, item); // ko rebinds array alter remove duplicate item ui.item.remove(); } } }; // bind $(element).sortable(sortablesetup); } }; }());

jquery knockout.js

No comments:

Post a Comment