Skip to content

Can't find variable item #12

Description

@reactCoder1

ReferenceError: can't find variable :item

MyCodeIs:....

`import React, { Component } from "react";

import { AppRegistry, View, Button, StyleSheet, Text } from 'react-native'
import LabelSelect from 'react-native-label-select'

class MyItskills extends Component {

constructor(props) {
    super(props);
    this.state = {
        arr: [{
            name: 'Microsoft Excel',
            isSelected: false,
            value: 1
        },
        {
            name: 'Microsoft Word',
            isSelected: false,
            value: 2
        },
        {
            name: 'Microsoft Access',
            isSelected: false,
            value: 3,
        },
        {
            name: 'Microsoft Office',
            isSelected: false,
            value: 4
        },
        {
            name: 'Microsoft Power Point',
            isSelected: false,
            value: 5
        },
        {
            name: 'Microsoft Exchage',
            isSelected: false,
            value: 6
        },
        {
            name: 'Micro Controls',
            isSelected: false,
            value: 7
        },
        {
            name: 'Micro Station',
            isSelected: false,
            value: 8
        },
        {
            name: 'Pcl',
            isSelected: false,
            value: 9
        },
        {
            name: 'Computers',
            isSelected: false,
            value: 10
        },
        {
            name: 'Emails',
            isSelected: false,
            value: 11
        }]
    };
    this.selectConfirm = this.selectConfirm.bind(this);
    this.deleteItem = this.deleteItem.bind(this);
}

selectConfirm(list) {
    let { arr } = this.state;
    for (let item of list) {
        let index = arr.findIndex(ele => ele === item);
        if (~index) arr[index].isSelected = true;
        else continue;
    }
    this.setState({ arr: arr });
}
deleteItem(item) {
    let {arr} = this.state;
    let index = arr.findIndex(a => a === item);
    arr[index].isSelected = false;
    this.setState({ arr: arr });
}

render() {
   

    return (
        <View style={styles.container}>
            <Text style={styles.text}>IT Skills</Text>
            <LabelSelect
                title="Checkbox"
                ref="select"
                style={styles.labelSelect}
                onConfirm={this.selectConfirm}>
                {this.state.arr.filter(item = item.isSelected).map((item, index) =>
                    <LabelSelect.Label
                        key={'label-' + index}
                        data={item}
                        onCancel={() => { this.deleteItem(item); }}
                    >
                        {item.name}
                    </LabelSelect.Label>
                )}
            </LabelSelect>
            {/* <Text style={styles.text}>Disable ItSkills</Text>
            <LabelSelect
                style={styles.LabelSelect}
                title="Checkbox"
                enable={false}
                onConfirm={this.selectConfirm}>
                {this.state.arr.filter(item => item.isSelected).map((item, index) =>
                    <LabelSelect.Label
                        key={'label-' + index}
                        data={item}
                        onCancel={() => { this.deleteItem(item); }}
                    ></LabelSelect.Label>
                )}
            </LabelSelect> */}


        </View>
    );
}

}
const styles = StyleSheet.create({
container:{
flex:1,
padding:10,
justifyContent:'center',
alignItems:"flex-start",
backgroundColor:"#e3eeee"
},
labelSelect:{
marginTop:5,
marginBottom:20,
padding:5,
borderWidth:1,
borderRadius:6,
borderStyle:'dashed',
borderColor:'#6dc2a2'
},
text:{
fontSize:16,
color:'rgb(13, 131, 144)'
}
});
export default MyItskills;
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions