Я только начинаю с ember.js. Я хочу обновить данные контроллера на основе запроса сервера, который был сделан другим контроллером; i.e: MyController должен обновить свое состояние, когда IndexController изменил свойство. Я думаю, что я прав, но я не уверен, как обновить шаблон на основе наблюдаемого изменения. Вот что у меня есть «сезам Сейчас:ember.js - обновить шаблон от любого наблюдаемого контроллера
<script type="text/x-handlebars" data-template-name="application">
<div>
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="index">
<form>
<label for="go">Data</label>
<input type="text" id="go" />
<button type="button" {{action "findData"}}>Find Data</button>
</form>
</script>
<script type="text/x-handlebars" data-template-name="my">
<ul>
{{#each entry in controller}}
<li>{{entry}}</li>
{{/each}}
</ul>
</script>
эти шаблоны, которые в настоящее время хранятся в index.html
var App = Ember.Application.create()
App.IndexController = Ember.Controller.extend({
myProperty: false,
findData: function() {
console.log("Requesting data from the server ..");
myProperty = true;
}
});
App.MyController = Ember.Controller.extend({
needs: ['index'],
myPropertyHasChanged: function() {
var propertyChanged = this.get('controllers.index.myProperty');
if (propertyChanged) {
console.log("property has changed");
return ["apple", "orange"];
}
}.observes('controllers.index.myProperty')
});
и это реальный ember.js код. Как я могу обновить данные в «моем» шаблоне, основываясь на каждом нажатии кнопки в шаблоне индекса? Он должен быть список из 2-х элементов («яблоко» и «апельсин»)