我刚刚开始与backbone.js并试图围绕建模概念。我想用骨干js来创建一个购物车应用程序,与第三方REST api(不是rails,不能修改)接口。backbone.js模型可以包含多个集合吗?
这是GET车内容JSON响应例如:
{
"_v" : "12.3",
"currency" : "USD",
"product_sub_total" : 96.00,
"product_total" : 86.00,
"shipping_total" : null,
"tax_total" : null,
"order_total" : null,
"product_items" :
[
{
"product_id" : "123",
"item_text" : "Product foo",
"quantity" : 2.00,
"product_name" : "foo",
"base_price" : 30.00,
"price" : 60.00
},
{
"product_id" : "456",
"item_text" : "Product foo",
"quantity" : 1.00,
"product_name" : "bar",
"base_price" : 40.00,
"price" : 40.00,
"price_adjustments" :
[
{
"promotion_id" : "10% off",
"promotion_link" : "http://example.com/dw/shop/v12_3/promotions/10_percent_off",
"item_text" : "10% off",
"price" : -4.00
}
]
}
],
"order_price_adjustments" :
[
{
"promotion_id" : "10$ off",
"promotion_link" : "http://example.com/dw/shop/v12_3/promotions/10_bugs_off",
"item_text" : "10$ off",
"price" : -10.00
}
]
}
望着这JSON数据,也有像“product_total”和“shipping_total”数据的聚集体件,并有包含在列表如“product_items”和“order_price_adjustments”。即使是单个“product_items”也可以嵌套“price_adjustments”列表。
如何在backbone.js中建立购物车模型?我应该为我看到的每个散列(“product_item”,“price_adjustment”)创建一个模型,然后对这些模型的集合进行建模,然后制作一个包含这些集合以及聚合数据的篮子模型?我不知道如何处理这...
我是Backbonejs的新手,但我非常确定Collections是一组多个模型。而不是相反。 – 2015-01-13 01:27:50