Monday, 12 August 2013

How To Remove Unwanted JSON Node Using KnockoutJS

How To Remove Unwanted JSON Node Using KnockoutJS

Guys..
I am having problem to post json data because i have no idea how to remove
one of json node (in this case ServiceOptions) during the ajax post back.
var model = function () {
var self = this;
self.CompanyName = ko.observable('');
self.ServiceType = ko.observable();
self.ServiceOptions = ko.observableArray(
[
{ value: 0, text: 'Dry Cleaning' },
{ value: 1, text: 'Dog Walking' }
]
);
self.Street1 = ko.observable('');
self.Street2 = ko.observable('');
self.Street3 = ko.observable('');
self.Suburb = ko.observable('');
self.PostCode = ko.observable('');
self.State = ko.observable('');
self.Telephone = ko.observable('');
self.Fax = ko.observable('');
self.IsActive = ko.observable(false);
this.Update_Click = function () {
alert(ko.toJSON(self));
};
this.Delete_Click = function () {
alert('delete');
};
};
$(document).ready(function () {
ko.applyBindings(new model);
});
When i click Update button i am getting
"CompanyName":"","ServiceOptions":[{"value":0,"text":"Dry
Cleaning"},{"value":1,"text":"Dog
Walking"}],"Street1":"","Street2":"","Street3":"","Suburb":"","PostCode":"","State":"","Telephone":"","Fax":"","IsActive":false}
I am still getting ServiceOptions as you can see on the JSON result above.
Any idea how to fix it ?

No comments:

Post a Comment