【问题标题】:What's the reason for the error being thrown on init() method?在 init() 方法上引发错误的原因是什么?
【发布时间】:2017-07-12 01:58:21
【问题描述】:

我使用https://www.npmjs.com/package/react-native-dynamodb 为我的项目实施 DynamoDB 访问。我使用了与该网站相同的代码。

唯一的问题是,我看不到我的.init() 方法是如何给我的:Unresolved function or method init() 将鼠标悬停在它上面(顺便说一下,我正在使用 WebStorm IDE)。我相信这就是我的应用程序无法运行的原因。下面是代码以及我在模拟器中遇到的错误。

Error in iOS Simulator

这是我的.js 文件:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { ScrollView, Text, View, Button } from 'react-native';
import { logout } from '../redux/actions/auth';
import DropdownMenu from 'react-native-dropdown-menu';
import Icon from './Icon';
import DynamoDB from 'react-native-dynamodb';

let dynamodb = DynamoDB.init({
    credentials: {
        AccessKeyId: 'Some key',
        SecretKey: 'Some key'
    }
    // region: 'us-east-1' - default, optional
    // version: '20120810' - default, optional
})

dynamodb.table('user_choice').PutItem(
    {
        name: 'Jack Sparrow',
        age: 30,
        captain: true
    },

    {
        ConditionExpression: "last_movie <> :movie",
        ExpressionAttributeValues: {
            ":movie": {"S": "Pirates of the Caribbean: On Stranger Tides"}
        }
    })
    .then((response) => console.log(response)) // AWS object response
    .catch((error) => {
        console.log(error)
    })

class Secured extends Component {
    render() {
        var data = [["Literacy Leaders"], ["Wrestling Camp"], ["Screenplay Writing"], ["Panetarium Workshop"]];

        return(
            <ScrollView style={{padding: 20}}>
                <Icon/>

                <Text style={{fontSize: 27}}>
                    {`Welcome ${this.props.username}`}
                </Text>

                <View style={{flex: 1}}>

                    <DropdownMenu style={{flex: 1}}
                                  bgColor={"purple"}  //the background color of the head, default is grey
                                  tintColor={"white"} //the text color of the head, default is white
                                  selectItemColor={"orange"} //the text color of the selected item, default is red
                                  data={data}
                                  maxHeight={410}  // the max height of the menu
                                  handler={(selection, row) => alert(data[selection][row])} >

                        <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}} >
                        </View>
                    </DropdownMenu>

                </View>

                <View style={{margin: 20}}/>

                <Button onPress={(e) => this.userLogout(e)} title="Logout"/>

            </ScrollView>
        );
    }
}

const mapStateToProps = (state, ownProps) => {
    return {
        username: state.auth.username
    };
}

const mapDispatchToProps = (dispatch) => {
    return {
        onLogout: () => { dispatch(logout()); }
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Secured);

【问题讨论】:

    标签: javascript ios reactjs react-native amazon-dynamodb


    【解决方案1】:

    我检查了react-native-dynamodb 的源代码,似乎DynamoDB 不是默认导出的,而是命名导出。

    尝试像这样导入它:

    import { DynamoDB } from 'react-native-dynamodb';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      • 2012-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多