the below code is working fine when i call it at the first time, however in the second call the gridviewmodel becomes messy and all data become redundant
$.ajax({
url: 'rest service uri',
type: 'GET',
data: parameters,
dataType: 'json',
crossDomain: true,
success: function (data) {
function gridviewModel() {
var self = this;
self.items = ko.mapping.fromJS(data);
self.columns = [
new column("Name", "name", "Asc"),
new column("URL", "name", "Asc"),
new column("Embargo Date", "name", "Asc"),
new column("Status", "name", "Asc"),
new column("Reviewer Name", "name", "Asc"),
new column("Approver Name", "name", "Asc")
];
};
ko.applyBindings(new gridviewModel());
}
I tried to clear the observable array using removeAll() but it doesn't work with me.
Any idea?
Just for any one may face this issue in the future i managed to fix it by call ko.mapping.fromJS(data, gridviewModel.items) in Knockout mapping plugin Full code is
var gridviewModel = {
items: ko.mapping.fromJS([]),
columns: [
new column("Name", "name", "Asc"),
new column("URL", "name", "Asc"),
new column("Embargo Date", "name", "Asc"),
new column("Status", "name", "Asc"),
new column("Reviewer Name", "name", "Asc"),
new column("Approver Name", "name", "Asc")
]
};
$(function () {
ko.applyBindings(gridviewModel, document.getElementById("wip"));
});
Hope this solves others issue.