nodejs表达req.session post方法

时间:2013-10-07 20:50:29

标签: node.js post express

我正试图在快递中建立一个简单的购物车。

req.session.cart.styles[req.params.a] = {
                "_id":style.id,
                "style":style.style,
                "a":style.a,
                "price":style.price,
                "desc":style.desc,
                "category":style.category,
                "color":style.colors,
                "quantity":1
             };

这是我的json:

"13123":
{
"style":"13123",
"a":"13123",
"price":2,
"desc":"askfjalsidjfalskdjflasidfjekajlsdkfj",
"img":"http://127.0.0.1:8080/views/img/asdf.jpg",
"imgs":["a","b","c"],
"category":"top",
"colors":[{"color":"red","prestock":50,"instock":10,"inactive":0},{"color":"off white","prestock":60,"instock":5,"inactive":0}],
"quantity":1}}

你可以看到'colors'是一个数组,是否只能获得一种颜色?如果按原样发布,它会重新调整所有颜色。

PS。

<form method="post" action="/style/cart/add/prestock/{{stylelist.a}}">
<input type="hidden" name="_id" value="_id">
<input type="hidden" name="style" value="style">
<input type="hidden" name="a" value="a">
<input type="hidden" name="price" value="price">
<input type="hidden" name="category" value="category">
<input type="hidden" name="quantity" value="1">      
<input class="return" type="checkbox" name="color" value="Red">
<input class="return" type="checkbox" name="color" value="Off White">
<input class="return" type="checkbox" name="color" value="Green">
</form>

1 个答案:

答案 0 :(得分:0)

是,引用数组索引,后跟属性:

style.colors[0].color, //returns red from your JSON