Mic*_*son 0 javascript knockout.js
我试图在视图模型序列化到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();
}
Run Code Online (Sandbox Code Playgroud)
ko.applyBindings(new PageViewModel());
window.loadFirebugConsole;
console.log(ko.toJSON(PageViewModel));
Run Code Online (Sandbox Code Playgroud)
谢谢米克
您正在尝试序列化函数而不是对象.将您的代码更新为:
var vm = new PageViewModel();
ko.applyBindings(vm);
window.loadFirebugConsole;
console.log(ko.toJSON(vm));
Run Code Online (Sandbox Code Playgroud)