153
rated 0 times
[
155]
[
2]
/ answers: 1 / hits: 17538
/ 10 Years ago, mon, march 10, 2014, 12:00:00
When the page loads I get the data by calling getGeneJSONData() and when I do a database udpate i call the same method to load the new data and I get the error You cannot apply bindings multiple times to the same element
Here's the code snips
var geneViewModel = null;
var Gene = function (data) {
data = data || {};
var self = this;
self.geneValue = data.GeneValue;
self.geneCode = ko.protectedObservable(data.GeneCode);
self.geneName = ko.protectedObservable(data.GeneName);
self.geneComments = ko.protectedObservable(data.GeneComments);
};
var ViewModel = function (items) {
var self = this;
var newGene = { geneValue: , geneCode: ko.protectedObservable(null), geneName: ko.protectedObservable(null), geneComments: ko.protectedObservable(null) };
self.genes = ko.observableArray(ko.utils.arrayMap(items, function (data) {
return new Gene(data);
}));
self.updateGene = function (gene) {
getGeneJSONData();
}
}
function getGeneJSONData() {
$.ajax({
type: GET,
url: urlPath + '/GetGenes',
dataType: json
}).done(function (result) {
if (result) {
if (result.Success) {
var geneData = result.Data;
geneViewModel = new ViewModel(geneData);
ko.applyBindings(geneViewModel);
}
}
});
};
$(document).ready(function ($) {
getGeneJSONData();
});
I am not sure why I'm getting this error on the data reload. Do I have to remove the bindings before applying them again?
More From » knockout.js