Created
July 28, 2015 20:12
-
-
Save martellaj/f6715f94de63d814b19e to your computer and use it in GitHub Desktop.
Binding Firebase items to List as an array instead of object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react'); | |
module.exports = React.createClass({ | |
renderList: function() { | |
if (this.props.items && Object.keys(this.props.items).length === 0) { | |
return <h4> | |
Add a todo to get started. | |
</h4> | |
} | |
else { | |
// Make an empty array (React can handle arrays while rendering JSX). | |
var children = []; | |
// Iterate over items and extract the text from each. | |
for (var i in this.props.items) { | |
children.push( | |
<li> | |
{this.props.items[i].text} | |
</li> | |
); | |
} | |
return children; | |
} | |
}, | |
render: function() { | |
return <ul> | |
{this.renderList()} | |
</ul> | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to change
this.bindAsObject
tothis.bindAsArray
in app.jsx!