Reactjs 此.onPressItem不是映射中的函数
我需要一个关于react native(使用的typescript)的帮助。 我正在映射状态,并调用call onpress函数,但不工作。 我不知道我真的需要帮助。 0000000000000000000000000000000000000000000000000 错误 代码Reactjs 此.onPressItem不是映射中的函数,reactjs,typescript,react-native,typescript-typings,Reactjs,Typescript,React Native,Typescript Typings,我需要一个关于react native(使用的typescript)的帮助。 我正在映射状态,并调用call onpress函数,但不工作。 我不知道我真的需要帮助。 0000000000000000000000000000000000000000000000000 错误 代码 import React,{Component}来自'React'; 从“react native”导入ReactNative; 从“./labsoft/labsoft.ui”导入{style}; const=requi
import React,{Component}来自'React';
从“react native”导入ReactNative;
从“./labsoft/labsoft.ui”导入{style};
const=require('lodash');
变量页:任意;
const tabbartabscroll=ReactNative.StyleSheet.flatte(styles.tabbartabscroll);
const labeltabscroll=ReactNative.StyleSheet.flatte(styles.labeltabscroll);
const spacingLabel=ReactNative.StyleSheet.flatte(styles.spacingLabelTabsScroll)
const spacingLabelActive=ReactNative.StyleSheet.flatte(styles.spacinglabelactivetabscroll)
导出接口项StabscrollProperties{
app?:any;//这在视图中是必需的
当前页面?:任何;
页数?:有吗
}
导出接口itemsTabsScrollState{
app?:any;//这在视图中是必需的
当前页面?:任何;
页数?:任何;
}
导出默认类ItemStabsCrollPage扩展组件{
构造函数(道具:ItemStabsCrollProperties){
超级(道具);
_TabsScrollPage=props.app;
此.state={
currentPage:this.props.currentPage,
页码:[
{name:this.props.pages.name}
]
}
}
get currentPage(){返回this.state.currentPage}
set currentPage(value){this.setState({currentPage:value})}
onPressItem(按键:数字){
console.log(“key”,key)
this.setState({currentPage:key})
_TabsScrollPage.navigateTo();
}
私有电流:任何;
render(){
this.\u current=this.state.currentPage
console.log(此.\u当前)
返回(
{
this.props.pages.map(函数(值:any,i:any){
返回(
{value.name}
)
})
}
);
}
}
使用箭头功能允许此
指向组件。更改:
this.props.pages.map(function (value: any, i: any) {
到
import React, { Component } from 'react';
import ReactNative from 'react-native';
import { styles } from './labsoft/labsoft.ui';
const _ = require('lodash');
var _TabsScrollPage: any;
const tabbarTabsScroll = ReactNative.StyleSheet.flatten(styles.tabbarTabsScroll);
const labelTabsScroll = ReactNative.StyleSheet.flatten(styles.labelTabsScroll);
const spacingLabel = ReactNative.StyleSheet.flatten(styles.spacingLabelTabsScroll)
const spacingLabelActive = ReactNative.StyleSheet.flatten(styles.spacingLabelActiveTabsScroll)
export interface itemsTabsScrollProperties {
app?: any; // this is required in view
currentPage?: any;
pages?: any
}
export interface itemsTabsScrollState {
app?: any; // this is required in view
currentPage?: any;
pages?: any;
}
export default class ItemsTabsScrollPage extends Component<itemsTabsScrollProperties, itemsTabsScrollState> {
constructor(props: itemsTabsScrollProperties) {
super(props);
_TabsScrollPage = props.app;
this.state = {
currentPage: this.props.currentPage,
pages: [
{ name: this.props.pages.name }
]
}
}
get currentPage() { return this.state.currentPage }
set currentPage(value) { this.setState({ currentPage: value }) }
onPressItem(key: number) {
console.log("key", key)
this.setState({ currentPage: key })
_TabsScrollPage.navigateTo();
}
private _current: any;
render() {
this._current = this.state.currentPage
console.log(this._current)
return (
<ReactNative.ScrollView horizontal={true} showsHorizontalScrollIndicator={false} decelerationRate="fast">
<ReactNative.View style={tabbarTabsScroll}>
{
this.props.pages.map(function (value: any, i: any) {
return (
<ReactNative.TouchableOpacity key={i} onPress={this.onPressItem(i)} style={this._current === i ? spacingLabelActive : spacingLabel}>
<ReactNative.Text style={labelTabsScroll}>{value.name}</ReactNative.Text>
</ReactNative.TouchableOpacity>)
})
}
</ReactNative.View>
</ReactNative.ScrollView >
);
}
}
this.props.pages.map(function (value: any, i: any) {
this.props.pages.map((value: any, i: any) => {