2
我有使用findOne的问题,因为它总是返回undefined。React findOne返回undefined在客户端
此代码:
Routine.js
Meteor.methods({
.... // Some lines missing
'routines.getRoutine'(routineId) {
check(routineId, String);
return Routines.findOne(routineId);
},
});
注:如果我做Routines.findOne(routineId)的执行console.log它正确地显示,我正在寻找的元素。
App.jsx
handleSubmit(event) {
event.preventDefault();
const comment = ReactDOM.findDOMNode(this.refs.comment).value.trim();
Meteor.call('routines.addComment', this.state.routine._id, comment);
let a = Meteor.call('routines.getRoutine', this.state.routine._id);
ReactDOM.findDOMNode(this.refs.comment).value = '';
this.setState({
routine: a,
});
}
在我Appjs不要紧,我如何努力 'A' 永远是不确定的,我究竟做错了什么?
感谢您的帮助!
貌似Meteor.call不同步返回一个值,也不会允许状态,通过'routines.addComment更新'。您可以尝试在addComment之后添加超时,以查看它是否在状态更改后定义。 – Scott