I would like to understand how to loop through an array from a database using ReactJS. For this particular instance I am using an IndexDB wrapper called dexie.js.
My React code is below. What I would like it to do is fill out {this.state.results.name}
with the entire array of stuff that I add to it once I fill out the two boxes and click the submit button.
As is, the code adds the values to the database. I am just having trouble understanding how to use React to query them.
var SisterChristian = React.createClass({
getInitialState:function(){
return {results:[{name:'', age:''}]}
},
zanzibar:function(){
var resname = document.getElementById('inputname').value;
var resage = document.getElementById('inputage').value;
var datastoring = new Dexie('MySpace');
datastoring.version(1).stores({
friends: 'name, age'
});
datastoring.open().catch(function(err){
alert('Oh no son:' +err);
});
datastoring.friends.each((friend)=>{
this.setState({results:[{name:resname, age:resage}] });
});
datastoring.friends.add({
name: resname,
age: resage
});
},
render:function(){
return (<div>
<input type="text" id="inputname" />
<input type="text" id="inputage" />
<input type="submit" value="Shipping And Handling" onClick={this.zanzibar}/>
<p>{this.state.results.name}</p>
</div>);}
});
ReactDOM.render(<SisterChristian/>, document.getElementById('bacon'));
You can also see it on CodePen, which will hopefully make it easier to see. http://codepen.io/jasonchenthrow/pen/GqXoyr
cannot be the descendant of
` error. Not sure what to attribute that to.
– Jason Chen Aug 02 '16 at 02:20