我正在尝试将viewmodel序列化为json,但我只在undefined
部分获得ko.toJSON(PageViewModel)
。有什么想法吗?
function PageViewModel() {
//Properties
this.Name = ko.observable();
this.Title = ko.observable();
this.Language = ko.observable();
//Seo
this.SEOKeywords = ko.observable();
this.SEODescription = ko.observable();
this.SEOIndexPage = ko.observable();
this.SEOGeoPositionLatitude = ko.observable();
this.SEOGeoPositionLongitude = ko.observable();
this.SEOGeoPositionPlaceName = ko.observable();
this.SEOGeoPositionRegion = ko.observable();
}
ko.applyBindings(new PageViewModel());
window.loadFirebugConsole;
console.log(ko.toJSON(PageViewModel));
由于 米克
答案 0 :(得分:5)
您正在尝试序列化函数而不是对象。将代码更新为:
var vm = new PageViewModel();
ko.applyBindings(vm);
window.loadFirebugConsole;
console.log(ko.toJSON(vm));