当源数据包含moment.js日期时,我使用敲除映射插件收到以下错误。
TypeError: this._d.getUTCDay is not a function
https://raw.github.com/timrwood/moment/develop/moment.js
Line 1300
我有一个非常简单的模型,如下所示。如果我使用
birthDate: new Date(2013, 6, 1)
它工作正常,但如果我将其更改为
birthDate: moment().add('days', -5)
它抛出上述错误。
var NS = NS || {};
$(function () {
NS.ViewModel1 = function (data) {
var self = this;
self.firstName = data && data.firstName || "Hello";
self.lastName = data && data.lastName || "There";
self.birthDate = data && data.birthDate || new Date(2000, 11, 17);
};
var data = {
firstName: "John",
lastName: "Doe",
//birthDate: new Date(2013, 6, 1) // Works
birthDate: moment().add('days', -5)
};
var vm1 = new NS.ViewModel1();
console.log(vm1);
ko.mapping.fromJS(data, {}, vm1);
console.log(vm1);
ko.applyBindings(vm1, document.getElementById("observableSection"));
});