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 –