javascript - Calling function from within Knockout Observable Array -
i have knockout observable array wish edit within javascript , html well. here code:
var listmodel = function(formula) { var self = this; self.formula = ko.observablearray(formula); this.mergeequation = function(op) { if (op.type == "ins") { self.formula.splice(op.position, 0, op.value); } else if (op.type == "del") { self.formula.splice(op.position, 1); } else { console.info("no match: " + op.value + op.position); } }; };
my variable op
json string. know how call mergeequation
function using html data-bind, how do within same js file? current code goes this:
ko.applybindings(new listmodel(formula)); //... //initializing of json object called op //... if (something) { mergeequation(op); }
but doesn't work. missing out step here? i've read on functions , extenders both seems overkill i'm trying here.
ps: here's sample of json structure i'm working with:
{"type":"ins", "clientid":1223, "version":0, "value":"hi", "position":0, "id":2736}
change :-
ko.applybindings(new listmodel(formula));
to
var vm = new listmodel(formula); ko.applybindings(vm);
so, vm thing can call mergeequation on
vm.mergeequation(op)
Comments
Post a Comment