【发布时间】:2015-01-06 12:02:49
【问题描述】:
更新对象日期时出错
Template.showCards.events({
...
},
'click #difficulty button': function(event) {
var incBy = event.target.value;
var today = moment();
var newDue = moment(today).add(incBy,'days');
Cards.update(
this._id, {
$set: {due: newDue}
}
);
}
});
知道为什么吗?
Meteor 更新了正确的 due 字段,但值变为 "Invalid date"。
这是完整的错误(Chrome 开发工具):
Exception while simulating the effect of invoking '/cards/update' Error: Sorting not supported on regular expression {stack: (...), message: "Sorting not supported on regular expression"} Error: Sorting not supported on regular expression
at Error (native)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2411:13)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2386:36)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2378:33)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2386:36)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2378:33)
at http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:1838:54
at http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:1474:21
at Array.some (native)
at Function._.some._.any (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:284:59)
【问题讨论】:
-
在事件处理程序中记录“incBy”时会发生什么?会不会是只需要
parseInt的字符串/整数问题? -
@richsilv 感谢您的回复!它是一个字符串。我做了一个改变:
var incBy = parseInt(event.target.value);但它仍然是同样的问题。似乎它是字符串还是 int 都没关系。 -
啊,是的,这可能无关紧要。见下文...