我有一個模板,它爲模型中的每條記錄創建一個組件。我想查找一個組件並在運行時根據其他模板中的事件更新其某個屬性。如何在DOM中找到插入的特定組件。 {{#each}} {{我的名}} {{/每}} 在Ember.js中查找組件並更改其屬性
<script type="text/x-handlebars" data-template-name="components/my-name">
Hi, my name is {{name}}.
</script>
var App = Ember.Application.create();
App.IndexRoute=Ember.Route.extend({
model:function(){
return dummyNames;
}
});
var dummyName={[name='John', name='Jane', name='Jade']};
該代碼會在屏幕上顯示的名字。現在我有另一個叫做change的模板。
<script type="text/x-handlebars" data-template-name="change">
<button {{action 'changeNow'}}></button>
</script>
App.ChangeController=Ember.Controller.extend({
actions:{
changeNow:function(){
//Here I want to find the component where the name is Jane and change it to Kate. How to do this?
}
}
});
你在哪裏顯示你的組件?哪個模板? {{我的名字}} – Rigel