Reputation: 26588
Let's I have the following code to map json object to model:
$.getJSON('{% url "api-planner-planner-list" %}?format=json').then(function(data){
planner = data[0];
planner_model = ko.mapping.fromJS(planner);
ko.applyBindings(planner_model);
});
How do I add a test function to the model to work with data-bind="click: test"
??
Upvotes: 0
Views: 663
Reputation: 3502
Your question is unclear what you want to achieve if you want to add click event after model binding you can do this before applyBindnng or you can define viewmodel and merge it with data. Both will work
$.getJSON('{% url "api-planner-planner-list" %}?format=json').then(function(data){ planner = data[0]; planner_model = ko.mapping.fromJS(planner); planner_model.test = function(){ //your code.. } ko.applyBindings(planner_model); });
Upvotes: 1