- Objective: - Breadcrumb: # 概念阐释 ## 语义 通过`{{#each}}{{/each}}`块和`{{this}}`行为来产生数组结果。 ## 语法 ### 数组 ```html {{#each newArray}} {{this}} {{/each}} ``` `newArray`是`main.js`中`context`里面的数组的名字 ```js const context = { newArray: ['1', '2', '3'] }; ``` ### 数组对象 ``` {{#each newArray}} {{this.property}} {{/each}} ``` `newArray`是`main.js`中`context`里面的数组的名字;`this.property`访问数组属性。 ```js const context = { newArray: [ {name:'1'}, {name:'2'}, {name3:'3'} ] } ``` # 实例 ### 数组 ```html <script id="eachHelper" type="text/x-handlebars-template"> {{#each newArray}} <div class="block"> {{this}} </div> {{/each}} </script> ``` ```js const context = { newArray: ['1', '2', '3'] }; ``` ### 数组对象 ```html <script id="eachHelper" type="text/x-handlebars-template"> {{#each newArray}} <p> this current shape is: {{this.name}}</p> {{/each}} </script> ``` ```js const context: { newArray: [ {name:'Triangle'}, {name:'square'}, {name:'circle'} ] } ``` # 相关内容 # 问题 - [练习题1](https://www.codecademy.com/courses/build-interactive-websites/lessons/learn-handlebars/exercises/handlebars-each-this-i) 🌟🌟 - [练习题2](https://www.codecademy.com/courses/build-interactive-websites/lessons/learn-handlebars/exercises/handlebars-each-this-ii) 🌟 - [练习题3:if和each一起用](https://www.codecademy.com/courses/build-interactive-websites/lessons/learn-handlebars/exercises/handlebars-if-each):给每个语言添加一个条件选择,如果是true,有时间学,如果为false没时间学 🌟 # 问题答案 # 参考资料