Redux 在 Meteor.call 内调度或获取 Meteor.call 值
Redux dispatch inside Meteor.call or get Meteor.call value
我的项目使用 Meteor 和 react-redux
要使 redux 正常工作,必须能够访问组件 this.props 中的调度函数。
然而,当我使用 Meteor.call 时,回调的 this
属性 不包含预期的 redux 函数 dispatch
。
所以这是我的 Meteor.call:
var testing;
Meteor.call('seed', mergedobj, function(err, seed){
if(err){
console.log('ERROR ERROR ERROR: when calling seed err', err);
if(err.error === 'SWE_RISE_TRANS_NEGATIVE'){
}
}else{
console.log('return of seed', seed)
console.log('this', this)
//this.props.dispatch(seedAction(seed))
testing = seed
}
})
console.log('testing', testing) //'INITIAL' and not seed!!
我要么需要更改回调的 this
以便我可以在回调内部调用 this.props.dispatch 要么我需要在回调外部获取种子值... ..
我如何实现这一目标?
如何获取回调范围之外的种子内部变量的值?
如何使用这种语法:
const dispatch = this.props.dispatch;
Meteor.call('seed', mergedobj, function(err, seed){
if(err){
// error handling here.
}else{
dispatch(seedAction(seed));
}
})
因此您不必处理 this
关键字。
我的项目使用 Meteor 和 react-redux
要使 redux 正常工作,必须能够访问组件 this.props 中的调度函数。
然而,当我使用 Meteor.call 时,回调的 this
属性 不包含预期的 redux 函数 dispatch
。
所以这是我的 Meteor.call:
var testing;
Meteor.call('seed', mergedobj, function(err, seed){
if(err){
console.log('ERROR ERROR ERROR: when calling seed err', err);
if(err.error === 'SWE_RISE_TRANS_NEGATIVE'){
}
}else{
console.log('return of seed', seed)
console.log('this', this)
//this.props.dispatch(seedAction(seed))
testing = seed
}
})
console.log('testing', testing) //'INITIAL' and not seed!!
我要么需要更改回调的 this
以便我可以在回调内部调用 this.props.dispatch 要么我需要在回调外部获取种子值... ..
我如何实现这一目标?
如何获取回调范围之外的种子内部变量的值?
如何使用这种语法:
const dispatch = this.props.dispatch;
Meteor.call('seed', mergedobj, function(err, seed){
if(err){
// error handling here.
}else{
dispatch(seedAction(seed));
}
})
因此您不必处理 this
关键字。