我想用 moment.js 格式化我的 knockoutjs 绑定日期。我的代码有什么问题?
var modelNots;
function NotsViewModel() {
var self = this;
self.msgs = ko.observableArray();
}
modelNots = new NotsViewModel();
var thediv=$("#notSection")[0];
ko.applyBindings(modelNots, thediv );
ko.bindingHandlers.Date = {
update: function (element, valueAccessor) {
var value = valueAccessor();
var date = moment(value());
var strDate = date.format('YYYY-MM-DD');
$(element).text(strDate);
}
};
html:
<div data-bind="foreach: msgs">
<div data-bind="text:Date"></div>
</div>