0

我正在尝试用快递制作一个简单的购物车。

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'是一个数组,有可能只得到一种颜色吗?如果我按原样发布,它会返回所有颜色。

附言。

<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>
4

1 回答 1

0

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

style.colors[0].color, //returns red from your JSON
于 2013-10-07T20:51:42.167 回答