admin管理员组文章数量:1023044
Im getting this type error when im trying to navigate to next view after getting json response.but my this.props.navigator.push({id:'HomeCaseList')}
works well if i user out side of my json response getting method.can any one help me here.
click event
<MKButton
style={{marginLeft:10, marginRight:10,marginTop:10,marginBottom:350,height:40, width:400}}
backgroundColor={'#fff'}
//shadowRadius={2}
//shadowOffset={{width:0, height:2}}
shadowOpacity={.7}
shadowColor="black"
onPress={
// navigator.push();
this.loginToApp.bind(this)
}>
login function
gotoNext() {
fetch('http://url/login/', {
credentials: 'same-origin',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'wasalaa',
password: 'a',
})
}).then(function(response) {
//console.log(response.headers.get('Content-Type'))
//console.log(response.headers.get('Date'))
//console.log(response.status)
//console.log(response.statusText)
//console.log('json',response
//console.log(response.headers.get('JSESSIONID'))
return response.json()
}).then(function(json){
console.log('login response',json)
if(json.message_code === "SUCCESS"){
console.log('user logged')
this.props.navigator.push({
id: 'HomeCaseList',
//sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
});
}
}).catch(function(err){
console.log('error', err)
})
}
Im getting this type error when im trying to navigate to next view after getting json response.but my this.props.navigator.push({id:'HomeCaseList')}
works well if i user out side of my json response getting method.can any one help me here.
click event
<MKButton
style={{marginLeft:10, marginRight:10,marginTop:10,marginBottom:350,height:40, width:400}}
backgroundColor={'#fff'}
//shadowRadius={2}
//shadowOffset={{width:0, height:2}}
shadowOpacity={.7}
shadowColor="black"
onPress={
// navigator.push();
this.loginToApp.bind(this)
}>
login function
gotoNext() {
fetch('http://url/login/', {
credentials: 'same-origin',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'wasalaa',
password: 'a',
})
}).then(function(response) {
//console.log(response.headers.get('Content-Type'))
//console.log(response.headers.get('Date'))
//console.log(response.status)
//console.log(response.statusText)
//console.log('json',response
//console.log(response.headers.get('JSESSIONID'))
return response.json()
}).then(function(json){
console.log('login response',json)
if(json.message_code === "SUCCESS"){
console.log('user logged')
this.props.navigator.push({
id: 'HomeCaseList',
//sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
});
}
}).catch(function(err){
console.log('error', err)
})
}
Share
Improve this question
asked Apr 9, 2016 at 14:52
hashhash
5,4167 gold badges41 silver badges59 bronze badges
1 Answer
Reset to default 3In callback this
refers to global scope(in browser it is window
in node.js it is global
, and if you use strict mode
this will be undefined
) and not for your ponent, you should set this
//....
.then(function(json) {
if (json.message_code === "SUCCESS") {
this.props.navigator.push({
id: 'HomeCaseList',
// sceneConfig: Navigator.SceneConfigs.FloatFromBottom
});
}
}.bind(this))
^^^^^
// ....
Im getting this type error when im trying to navigate to next view after getting json response.but my this.props.navigator.push({id:'HomeCaseList')}
works well if i user out side of my json response getting method.can any one help me here.
click event
<MKButton
style={{marginLeft:10, marginRight:10,marginTop:10,marginBottom:350,height:40, width:400}}
backgroundColor={'#fff'}
//shadowRadius={2}
//shadowOffset={{width:0, height:2}}
shadowOpacity={.7}
shadowColor="black"
onPress={
// navigator.push();
this.loginToApp.bind(this)
}>
login function
gotoNext() {
fetch('http://url/login/', {
credentials: 'same-origin',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'wasalaa',
password: 'a',
})
}).then(function(response) {
//console.log(response.headers.get('Content-Type'))
//console.log(response.headers.get('Date'))
//console.log(response.status)
//console.log(response.statusText)
//console.log('json',response
//console.log(response.headers.get('JSESSIONID'))
return response.json()
}).then(function(json){
console.log('login response',json)
if(json.message_code === "SUCCESS"){
console.log('user logged')
this.props.navigator.push({
id: 'HomeCaseList',
//sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
});
}
}).catch(function(err){
console.log('error', err)
})
}
Im getting this type error when im trying to navigate to next view after getting json response.but my this.props.navigator.push({id:'HomeCaseList')}
works well if i user out side of my json response getting method.can any one help me here.
click event
<MKButton
style={{marginLeft:10, marginRight:10,marginTop:10,marginBottom:350,height:40, width:400}}
backgroundColor={'#fff'}
//shadowRadius={2}
//shadowOffset={{width:0, height:2}}
shadowOpacity={.7}
shadowColor="black"
onPress={
// navigator.push();
this.loginToApp.bind(this)
}>
login function
gotoNext() {
fetch('http://url/login/', {
credentials: 'same-origin',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'wasalaa',
password: 'a',
})
}).then(function(response) {
//console.log(response.headers.get('Content-Type'))
//console.log(response.headers.get('Date'))
//console.log(response.status)
//console.log(response.statusText)
//console.log('json',response
//console.log(response.headers.get('JSESSIONID'))
return response.json()
}).then(function(json){
console.log('login response',json)
if(json.message_code === "SUCCESS"){
console.log('user logged')
this.props.navigator.push({
id: 'HomeCaseList',
//sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
});
}
}).catch(function(err){
console.log('error', err)
})
}
Share
Improve this question
asked Apr 9, 2016 at 14:52
hashhash
5,4167 gold badges41 silver badges59 bronze badges
1 Answer
Reset to default 3In callback this
refers to global scope(in browser it is window
in node.js it is global
, and if you use strict mode
this will be undefined
) and not for your ponent, you should set this
//....
.then(function(json) {
if (json.message_code === "SUCCESS") {
this.props.navigator.push({
id: 'HomeCaseList',
// sceneConfig: Navigator.SceneConfigs.FloatFromBottom
});
}
}.bind(this))
^^^^^
// ....
本文标签: javascriptTypeError undefined is not an object (evaluating 39thisprops39)React NativeStack Overflow
版权声明:本文标题:javascript - TypeError: undefined is not an object (evaluating 'this.props') - React Native - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745575538a2156994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论