2016-04-09 21 views
0

Başlık her şeyi belirtir. Yinelemeyi gidonlarla iç içe geçirmeye çalışıyorum ama doğru anlayamıyorum. Kodu, temel şartlar olarak gördüklerime göre ayrıştırdım, ama benim sorunum başka bir yerde yatıyorsa, hepsini gönderebilirim.Gidonlarla ilgili sorun - yuvalanmış yinelemeler farklı olduğunda aynı değerin kaydedilmesi

İşte 'veri' olarak döndürdüğüm dizi.

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

Ve gidon:

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

Ve gidon çıktı 10 JK Rowlings değil birden yazarlar olduğunu. Hayatım boyunca bunu anlayamıyorum. Çeşitli gidon formatlarını denediniz ve yine de doğru alamıyorsunuz.

İlk yazım burada. Üzgünüm, bu açık değilse. Herhangi bir yardım için teşekkür ederiz. Teşekkür ederim!

Düzenleme: Ve evet, her nesne için yalnızca bir yazar olsaydı, yuvalanmış bir dizi kullanmak zorunda kalmazdım, ancak birden çok yazar olduğunda bazı örnekler vardır (örnek olarak değil).

cevap

0

data değeriniz geçersiz görünüyor. Üst düzey dizideki öğeler virgülle ayrılmaz. O virgül ekledi kez

ben http://tryhandlebarsjs.com/ bu çalışma cezası almak başardı:

believe it is olarak

enter image description here

Belki veri ayarlı değil?

+0

Hey Scott - geri bildiriminiz için teşekkürler. Çok fazla hemming ve tacizden sonra işe koyuldum. Aslında JK Rowling'in neden kendini klonlandığını hala bilmiyorum-- Yukarda yayınladığım diziyi oluşturan kodun yeniden yazılmasını ve tüm bunların çalışmasını sağladım. Muhtemelen daha da iyisi için - yeniden yazma çok daha zarif bir koddu, orijinalin ve okunabilirliğin çok daha uzun olması halinde, sadece% 60'dı. Yorumunuzdan dolayı, gidon tarafında bir sorun olmadığını biliyordum, bu yüzden bana biraz kafa çizmekten kurtuldunuz. Tekrar teşekkürler! – jamesfreeman