0
我开始使用离子框架,并且我被困在创建并在另一个数组内调用数组。另一个数组内的Javascript数组
我有下面的代码在我books.js
:
.factory('Books', function() {
// books data
var books = [{
id: 0,
title: 'Sample Title',
author: 'Sample Author',
category: 'Horor, Fiction',
cover: '/cover.jpeg',
details: 'some details about the book',
// my first attempt to create an array to store chapters info
chapters: [
{
name: 'Chapter 1',
filename: 'chapter1.html',
},
{
name: 'Chapter 2',
filename: 'Chapter2.html',
}
]
}, {
id: 1,
title: 'Sample Title Two',
author: 'Sample Author two',
category: 'Horor, Fiction',
cover: '/cover.jpeg',
details: 'some details about the book',
// my first attempt to create an array to store chapters info
chapters: [
{
name: 'Chapter 1',
filename: 'chapter1.html',
},
{
name: 'Chapter 2',
filename: 'Chapter2.html',
}
]
},
访问数据时
,我使用{{book.title}}
和它将输出本书的书名。但是我不确定如何返回章节的值,因为每本书都有不同的章节数。
也许为每个章节分配章节ID并调用该ID?
你试过book.chapters [0]。名称? –
获取数组的长度然后循环从0到(number - 1) –
books [0] .chapters [0] .name –