0

我正在尝试将视图模型序列化为 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));

谢谢米克

4

1 回答 1

5

您正在尝试序列化函数而不是对象。将您的代码更新为:

var vm = new PageViewModel();
ko.applyBindings(vm);
window.loadFirebugConsole;
console.log(ko.toJSON(vm));
于 2012-12-29T12:33:03.493 回答