【发布时间】:2015-11-20 09:31:39
【问题描述】:
我一直在寻找一整天,通过从我的产品列表 (this.props.products) 中选择一个新项目来更新我的 ShoppingCart (this.props.shoppingCart)..
我找到了一种方法,但它看起来确实很麻烦和复杂,那就是使用这样的调度程序:
如果我没记错的话,这还需要 npm-package flex 和 node.js ?这并不理想,因为我使用的是 Visual Studio 和 ReactJS.NET..
那么...地球我怎么能以简单易管理的方式做到这一点?
全球调度员:
var ShoppingCartStore = {
shoppingCart: [],
dispatcher: new Dispatcher(),
addToCart: function (item) {
this.shoppingCart.push(item);
this.dispatcher.dispatch({
actionType: 'updated',
data: this.shoppingCart
});
},
};
用法:
addToCart: function (e) {
var shoppingCartItem = {
name: this.props.productData.name,
price: this.props.productData.price,
description: this.props.productData.description
};
ShoppingCartStore.dispatcher.subscribe(function () {
});
ShoppingCartStore.addToCart(shoppingCartItem);
},
如何更新?
var ShoppingCartBig = React.createClass({
componentDidMount: function () {
ShoppingCartStore.dispatcher.subscribe(function (o) {
this.setState({ shoppingCart: o.data });
});
},
【问题讨论】:
标签: c# asp.net reactjs reactjs.net