2017-07-12 178 views
0

我使用https://www.npmjs.com/package/react-native-dynamodb为我的项目实现了DynamoDB访问。我使用了与该网站相同的确切代码。init()方法抛出错误的原因是什么?

唯一的问题是,我看不到我的.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); 

回答

0

我检查的react-native-dynamodb的源代码,似乎DynamoDB不导出为默认值,但一个叫出口。

尝试导入这样的:

import { DynamoDB } from 'react-native-dynamodb'; 
相关问题