加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

反应 – 原生的 – 这个参考在方法中得不到定义

发布时间:2020-12-15 20:51:36 所属栏目:百科 来源:网络整理
导读:我试图在我的项目 https://github.com/rt2zz/react-native-drawer中使用这个插件.我可以正确运行示例,但是集成它有问题. 我在方法openDrawer中收到错误. “看不清楚属性抽屉的未定义” 我猜测我没有以正确的方式定义和使用该类,因为它应该是(我是javascript
我试图在我的项目 https://github.com/rt2zz/react-native-drawer中使用这个插件.我可以正确运行示例,但是集成它有问题.

我在方法openDrawer中收到错误. “看不清楚属性抽屉的未定义”

我猜测我没有以正确的方式定义和使用该类,因为它应该是(我是javascript OOP的新手),例如它使用React.createClass({不像我的扩展组件并具有构造函数).

我班的相关代码如下.

class Search extends Component {

    constructor(props) {
        super(props);
        this.state = {
            isLoading: true,dataSource: new ListView.DataSource({
               rowHasChanged: (row1,row2) => row1 !== row2
            })
        };
    }

    openDrawer(){
        this.refs.drawer.open()
    }

    getInitialState(){
        return {
          drawerType: 'overlay',}
    }

渲染是

render() {
        if (this.state.isLoading) {
            return this.renderLoadingView();
        }

        var controlPanel = <MyControlPanel closeDrawer={() => {this.refs.drawer.close()}} />

        return (


            <View>
                <View style={styles.topBar}>

                    <Drawer
                        ref="drawer"
                        >
                        <MyMainView
                          />
                    </Drawer>

                    <Text style={styles.topBarMenu}>&#9776;</Text>
                    <Text style={styles.topBarTitle}>?????????</Text>
                    <Text style={styles.topBarRight}></Text>
                </View>
我认为最好是回到使用createClass.创建类(扩展)的ES6方法与createClass相比有很多缺点:方法是未绑定的(即“这”不一定指向对象),也不能使用相当有用的mixin.未绑定的方法是您遇到的问题.您也可以解决这个问题,以防您调用该方法的位置并绑定该方法(在javascript中查找方法绑定,例如: http://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读