ember.js 可组合组件
例子
里面parent-component.hbs
{{yield (hash
child=(
component 'child-component'
onaction=(action 'parentAction')
)
)}}里面parent-component.js
export default Ember.Component.extend({
actions: {
//我们将此操作传递给孩子,由其自行决定调用
parentAction(childData) {
alert('Data from child-component: ' + childData);
}
}
});里面child-component.js
export default Ember.Component.extend({
//单击时,我们调用从父级传递给我们的操作
click() {
let data = this.get('data');
this.get('onaction')(data);
}
});里面usage.hbs
{{#parent-component as |ui|}}
{{#each model as |item|}}
{{ui.child data=item}}
{{/each}}
{{/parent-component}}
热门推荐
10 新年简单祝福语简短好看
11 古风婚礼祝福语唯美简短
12 给孙子祝福语简短独特
13 小朋友祝福语简短的话
14 祝福语老人简短话语
15 二胎祝福语简短霸气
16 新年祝福语简短的个性
17 梳子结婚蛋糕祝福语简短
18 婚礼父母在家祝福语简短