我有一个看起来像的数据
var categories = [
{
name: 'Animals',
img: 'animals.jpg',
list: [{name: 'Cat', img: 'cat.jpg', state: 'hidden'}, {name: 'Dog', img: 'dog.jpg', state: 'hidden'}, {name: 'Zebra', img: 'zebra.jpg', state: 'hidden'}, {name: 'Rabbit', img: 'rabbit.jpg', state: 'hidden'}]
},
{
name: 'Birds',
img: 'birds.jpg',
list: [{name: 'Eagle', img: 'eagle.jpg', state: 'hidden'}, {name: 'Owl', img: 'owl.jpg', state: 'hidden'}, {name: 'Parrot', img: 'parrot.jpg', state: 'hidden'}, {name: 'Swan', img: 'swan.jpg', state: 'hidden'}]
},
{
name: 'Fruits',
img: 'fruits.jpg',
list: [{name: 'Apple', img: 'apple.jpg', state: 'hidden'},{name: 'Cherry', img: 'cherry.jpg', state: 'hidden'},{name: 'Banana', img: 'banana.jpg', state: 'hidden'}, {name: 'Strawberry', img: 'strawberry.jpg', state: 'hidden'}, {name: 'Mango', img: 'mango.jpg', state: 'hidden'}, {name: 'Orange', img: 'orange.jpg', state: 'hidden'}, {name: 'Pomegranate', img: 'pomegranate.jpg', state: 'hidden'}, {name: 'Jackfruit', img: 'jackfruit.jpg', state: 'hidden'}]
},
{
name: 'Flowers',
img: 'flowers.jpg',
list: [{name: 'Rose', img: 'rose.jpg', state: 'hidden'}, {name: 'Tulip', img: 'tulip.jpg', state: 'hidden'}, {name: 'Hibiscus', img:'hibiscus.jpg', state: 'hidden'}, {name: 'Sunflower', img: 'sunflower.jpg', state: 'hidden'}]
}
];
在这里,我将类别用作集合,将每个类别用作模型。我想要的是从这个集合中获取一组随机的对象,它们在每个模型的列表中。假设我随机点击,我可能会得到菠萝蜜、玫瑰、苹果、鹰、猫、郁金香的列表。
不太确定我创建的结构是否正确。我应该为每个类别的对象列表数组中的每个项目使用模型吗?