在使用react-native 时 查询空表时没有返回结果
没有返回结果返回的是啥?还是说返回异常了?
抱歉,排查了问题是 回调之后不执行
todo.save().then(function (todo) { console.log("this props",this.props) //为undefined this.saveSuccess();//不执行 }, function (error) { // 异常处理 this.refs.toast.show(error) });
既然 console.log("this props",this.props) 打印出了 undefined,那么说明这一行执行到了,至于下一行出了什么问题需要你自行查一下(估计是里面抛异常了)。
console.log("this props",this.props)
就是 在save的回调里面 拿不到this了..
建议了解一下 JS 的箭头函数与作用域的知识。
谢谢,我没留意这,改成这样就好了
todo.save().then((todo)=> { console.log("this props",this.props) this.saveSuccess(); }, function (error) { // 异常处理 this.refs.toast.show(error) });