2016-04-09 3 views
0

タイトルはすべてです。私はハンドルバーで反復を入れようとしていますが、それを正しく得ることはできません。私は裸の必需品とみなしたコードを解析しましたが、私の問題が他のどこかにある場合、私はそのすべてを投稿できます。ハンドルバーの問題 - ネストされた繰り返し - 異なる値が必要なときに同じ値を記録する

ここは「データ」として返されている配列です。

[{ 
    id: 4, 
    title: 'Think Python', 
    cover_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/think_python.jpg', 
    book_id: 2, 
    author_id: 4, 
    firstname: 'Allen', 
    lastname: 'Downey', 
    bio: 'Allen Downey is a Professor of Computer Science at Olin College of Engineering. He has taught at Wellesley College, Colby College and U.C. Berkeley. He has a Ph.D. in Computer Science from U.C. Berkeley and Master\'s and Bachelor\'s degrees from MIT.', 
    author_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/allen_downey.jpg', 
    authors: [{ 
    name: 'Allen Downey', 
    id: 4 
    }] 
} { 
    id: 5, 
    title: 'Learning React Native', 
    cover_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/learning_react_native.jpg', 
    book_id: 3, 
    author_id: 5, 
    firstname: 'Bonnie', 
    lastname: 'Eisenman', 
    bio: 'Bonnie,Eisenman,"Bonnie Eisenman is a software engineer at Codecademy, with previous experience at Fog Creek Software and Google. She has spoken at several conferences on topics ranging from ReactJS to musical programming and Arduinos. In her spare time, she enjoys building electronic musical instruments, tinkering with hardware projects, and laser-cutting chocolate. Find her on Twitter as @brindelle.', 
    author_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/bonnie_eisenman.jpg', 
    authors: [{ 
    name: 'Bonnie Eisenman', 
    id: 5 
    }] 
} { 
    id: 6, 
    title: 'You Don\'t Know JS: ES6 & Beyond', 
    cover_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/es6_and_beyond.jpg', 
    book_id: 4, 
    author_id: 6, 
    firstname: 'Kyle', 
    lastname: 'Simpson', 
    bio: 'Kyle Simpson is an Open Web Evangelist who\'s passionate about all things JavaScript. He\'s an author, workshop trainer, tech speaker, and OSS contributor/leader.', 
    author_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/kyle_simpson.jpg', 
    authors: [{ 
    name: 'Kyle Simpson', 
    id: 6 
    }] 
} { 
    id: 6, 
    title: 'You Don\'t Know JS: Scope & Closures', 
    cover_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/scope_and_closures.jpg', 
    book_id: 5, 
    author_id: 6, 
    firstname: 'Kyle', 
    lastname: 'Simpson', 
    bio: 'Kyle Simpson is an Open Web Evangelist who\'s passionate about all things JavaScript. He\'s an author, workshop trainer, tech speaker, and OSS contributor/leader.', 
    author_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/kyle_simpson.jpg', 
    authors: [{ 
    name: 'Kyle Simpson', 
    id: 6 
    }] 
} { 
    id: 6, 
    title: 'You Don\'t Know JS: Async & Performance', 
    cover_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/async_and_performance.jpg', 
    book_id: 6, 
    author_id: 6, 
    firstname: 'Kyle', 
    lastname: 'Simpson', 
    bio: 'Kyle Simpson is an Open Web Evangelist who\'s passionate about all things JavaScript. He\'s an author, workshop trainer, tech speaker, and OSS contributor/leader.', 
    author_url: 'https://s3-us-west-2.amazonaws.com/assessment-images/galvanize_reads/photos/kyle_simpson.jpg', 
    authors: [{ 
    name: 'Kyle Simpson', 
    id: 6 
    }] 
} { 
    id: 13, 
    title: 'A Darker Shade of Magic', 
    cover_url: 'http://ecx.images-amazon.com/images/I/51RYeVqlj9L._SX331_BO1,204,203,200_.jpg', 
    book_id: 10, 
    author_id: 13, 
    firstname: 'Victoria E.', 
    lastname: 'Schwab', 
    bio: 'Victoria [V.E.] Schwab is an American author known for her adult books under V.E. Schwab and her young adult and middle grade books under Victoria Schwab. Most notable publications include: Vicious and A Darker Shade of Magic.', 
    author_url: 'http://prodimage.images-bn.com/cimages/0000012524053_p0_v1_s280x185.jpg', 
    authors: [{ 
    name: 'Victoria E. Schwab', 
    id: 13 
    }] 
} { 
    id: 14, 
    title: 'Harry Potter', 
    description: 'A magical wizard finds his way in the world.', 
    cover_url: 'https://upload.wikimedia.org/wikipedia/en/b/bf/Harry_Potter_and_the_Sorcerer\'s_Stone.jpg', 
    book_id: 11, 
    author_id: 14, 
    firstname: 'J. K. ', 
    lastname: 'Rowling', 
    bio: 'A brilliant Englishwoman. ', 
    author_url: 'https://pbs.twimg.com/profile_images/703332968232820739/vu_rCwh5.jpg', 
    authors: [{ 
    name: 'J. K. Rowling', 
    id: 14 
    }] 
}] 

そしてハンドルバー:

{{#data}} 
{{#each this.authors}} 
<ul>{{name}}</ul> 
{{/each}} 
{{/data}} 

そして、ハンドル出力は10 JK Rowlings、ない複数の著者です。私は私の人生のためにこれを理解することはできません。いろいろなハンドルバーのフォーマットを試しましたが、それでも正しいものは得られません。

私の最初の投稿はここにあります。これがはっきりしない場合は申し訳ありません。助けをお待ちしています。ありがとうございました!

編集:はい、オブジェクトあたり1人の作者であれば、ネストされた配列を使用する必要はありませんが、複数の作者が存在する場合(例ではない)のインスタンスがあります。

答えて

0

dataの値は無効です。最上位配列の項目はコンマで区切られていません。私はそれらのコンマを追加したら、

私は http://tryhandlebarsjs.com/にこの作業罰金を得ることができた:

あなたはそれがあると考えているよう

enter image description here

おそらく、あなたのデータが設定されていませんか?

+0

あなたのフィードバックに感謝します。たくさんのヘミングとハングをした後、私はそれを働かせました。私は実際にはJKローリングがなぜ自分自身をクローンしていたのかまだ分かりません。上に掲載した配列を生成したコードを書き直してしまったので、それがすべて動作しました。おそらく、より良いために - 書き直しははるかに読みやすく、オリジナルの場合はわずか60%の長さではるかにエレガントなコードでした。あなたのコメントのため、私はそれがハンドルバー側で問題ではなかったことを知っていたので、あなたは間違いなく私にいくつかのヘッドスクラッチを保存しました。再度、感謝します! – jamesfreeman

関連する問題