Created
June 20, 2015 20:03
-
-
Save mweststrate/2408f879252a33de322a to your computer and use it in GitHub Desktop.
shopping cart views
This file contains 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 CartView = React.createClass({ | |
render: function() { | |
function renderEntry(entry) { | |
return (<CartEntryView entry={entry} cart={this.props.cart} key={entry.id} />); | |
} | |
return (<div> | |
<ul id="cart">{this.props.cart.entries.map(renderEntry)}</ul> | |
<div><b>Total: <span id="total">{this.props.cart.total}</span></b></div> | |
</div>) | |
} | |
}); | |
var CartEntryView = React.createClass({ | |
render: function() { | |
return (<li> | |
<button onClick={this.removeArticle}>«</button> | |
<span>{this.props.entry.article.name}</span> | |
<span>{this.props.entry.amount}</span> | |
</li>); | |
}, | |
removeArticle: function() { | |
if (--this.props.entry.amount < 1) | |
this.props.cart.entries.splice(this.props.cart.entries.indexOf(this.props.entry), 1); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment