2016-04-09 3 views
0

Der Titel sagt alles. Ich versuche, Iterationen mit dem Lenker zu verschachteln, aber ich finde es nicht richtig. Ich habe den Code auf das reduziert, was ich für das Wesentliche gehalten habe, aber wenn mein Problem woanders liegt, kann ich das alles posten.Probleme mit den Lenkern-- verschachtelte Iterationen, die denselben Wert protokollieren, wenn sie anders sein sollten

Hier ist das Array, das ich als 'Daten' zurückschicke.

[{ 
    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 
    }] 
}] 

Und die Lenker:

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

Und der Lenker Ausgang ist 10 JK Rowlings, nicht mehrere Autoren. Ich kann das nicht für das Leben von mir herausfinden. Habe verschiedene Lenkerformate ausprobiert und kann es trotzdem nicht richtig hinkriegen.

Mein erster Beitrag hier. Tut mir leid, wenn das nicht klar ist. Schätze jede Hilfe. Vielen Dank!

Edit: Und ja, wenn es nur ein Autor pro Objekt wäre, müsste ich kein verschachteltes Array verwenden, aber es gibt einige Instanzen (nicht im Beispiel), wenn mehrere Autoren existieren.

Antwort

0

Ihr data Wert scheint ungültig zu sein. Die Elemente im Array der obersten Ebene sind nicht durch Kommas getrennt.

konnte ich dieses adaequat auf http://tryhandlebarsjs.com/ erhalten, sobald ich diese Komma hinzugefügt:

ist

enter image description here

Vielleicht Ihre Daten nicht festgelegt ist, wie Sie glauben, es ist?

+0

Hey Scott - danke für dein Feedback. Nach viel Saum und Hauen habe ich es zur Arbeit gebracht. Ich weiß eigentlich immer noch nicht, warum JK Rowling sich selbst geklont hat - ich habe den Code neu geschrieben, der das Array generiert hat, das ich oben gepostet habe, und das hat alles funktioniert. Wahrscheinlich zum Besseren, auch - die Umschrift war viel eleganter Code, bei nur 60% der Länge, wenn das Original und viel besser lesbar ist. Aufgrund deines Kommentars wusste ich, dass es kein Problem auf der Seite des Lenkers war, also rettest du mir definitiv ein bisschen Kopfschütteln. Danke noch einmal! – jamesfreeman

Verwandte Themen