简体   繁体   中英

Use Json object inside a function (React-Native)

I am new to react native, hope i can explain my self enough so you'll understand. I am trying to create a countdown to specific item on screen. I have a working ListView which creates rows of items from a local Json (for now). In each row i have a button which trigger a countdown specific so each row. ( onPress= function.bind(this) ) I know my countdown algorithm works, because i tested it before with hard-coded data.

In the onPress function, i'm trying to do dateTime = json_file.Time.split(' ') to split between date and time but i got the error

Cannot read property 'split' of undefined

Maybe the function doesn't "know" my Json file? Any ideas?

Thanks.

The JSON is probably an array if you are creating rows of items from it. So you would have to do json_file[i].Time.split(' ') where i is the index of the row being pressed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM