jsFiddle:http: //jsfiddle.net/brandondurham/g3exx/
如何在我的模型中创建各种 observableArrays 之间的关系?例如,在我的模型中,我有一个cartItems
数组,该数组中的每个项目都有一个嵌套itemFreebies
数组和一个itemType
属性。客户只有在他们的购物车中有订阅时"itemType" : "subscription"
(
创建这些类型的条件关系的最佳方法是什么?
这是我在模型中使用的对象:
{
"cartItems" : [
{
"itemName" : "Product 1",
"itemDesc" : "Product 1 description",
"itemType" : "subscription",
"itemPrice" : 299,
"itemFreebies" : false
}, {
"itemName" : "Product 2",
"itemDesc" : "Product 2 description",
"itemType" : "desktop",
"itemPrice" : 4499,
"itemFreebies" : [{
"freebieName" : "Product 2 freebie",
"freebieDesc" : "Product 2 freebie description",
"freebieOriginalPrice" : 99
}]
}, {
"itemName" : "Product 3",
"itemDesc" : "Product 3 description",
"itemType" : "desktop",
"itemPrice" : 8999,
"itemFreebies" : [{
"freebieName" : "Product 3 freebie",
"freebieDesc" : "Product 3 freebie description",
"freebieOriginalPrice" : 99
}]
}, {
"itemName" : "Product 4",
"itemDesc" : "Product 4 description",
"itemType" : "desktop",
"itemPrice" : 99,
"itemFreebies" : [{
"freebieName" : "Product 4 freebie",
"freebieDesc" : "Product 4 freebie description",
"freebieOriginalPrice" : 99
}]
}, {
"itemName" : "Product 5",
"itemDesc" : "Product 5 description",
"itemType" : "webfont",
"itemPrice" : 49,
"itemFreebies" : false
}
]
}