Я работаю над игрушечным приложением, чтобы изучить Ember. У меня есть рецепты, которые относятся к стилям. Стиль состоит только из атрибута имени (а также неявного идентификатора). У меня возникли проблемы с настройкой поля выбора в новом шаблоне, чтобы выбрать стиль рецепта.
Вот что у меня сейчас есть для маршрутов, контроллеров и шаблонов:
Маршруты:
App.RecipesNewRoute = Ember.Route.extend({
model: function() {
return App.Recipe.createRecord({
title: '',
description: '',
instructions: ''
});
},
setupController: function(controller, model) {
controller.set('content', model);
}
});
Контроллеры:
App.RecipesController = Ember.ArrayController.extend({});
App.RecipesNewController = Ember.ObjectController.extend({
create: function() {
this.transitionToRoute('recipes.show', this.content);
},
cancel: function() {
this.content.deleteRecord();
this.transitionToRoute('recipes.index');
},
buttonTitle: 'Add Beer Recipe'
});
Шаблоны:
recipes/new и частичная форма:
<script type="text/x-handlebars" data-template-name="recipes/new">
{{ partial 'recipes/form' }}
</script>
<script type="text/x-handlebars" data-template-name="recipes/_form">
{{ title }}
<form>
<fieldset>
<div>
<label {{bindAttr for="titleField.elementId"}}>Title</label>
{{view Ember.TextField valueBinding='title' name='title' viewName='titleField'}}
</div>
<div>
<label>Style</label>
{{view Ember.Select valueBinding='style' name='style' viewName='styleField' contentBinding='App.Style.find()'}}
</div>
<div>
<label {{bindAttr for='descriptionField.elementId'}}>Description</label>
{{view Ember.TextArea valueBinding='description' name='description' viewName='descriptionField'}}
</div>
<div>
<label {{bindAttr for='instructionsField.elementId'}}>Instructions</label>
{{view Ember.TextArea valueBinding='instructions' name='instructions' viewName='instructionsField'}}
</div>
<a href='#' {{action create target='controller'}}>{{buttonTitle}}</a>
</fieldset>
</form>
<a href='#' {{action cancel target='controller'}}>Cancel</a>
</script>
Главный вывод: {{view Ember.Select valueBinding='style' name='style' viewName='styleField' contentBinding='App.Style.find()'}}
Я также пытался настроить переменную стилей в контроллере: в RecipesNewController: styles: App.Style.find()
и в представлении {{view Ember.Select valueBinding='style' name='style' viewName='styleField' contentBinding='styles' optionValuePath='styles.id' optionLabelPath='styles.name'}}
а также в setupController: controller.set('styles', App.Style.find())
маршрута (с тем же кодом просмотра, что и при установке его в контроллере).
Любая помощь была бы отличной, я уверен, что это что-то простое.
Спасибо
Обновить
Так что я думаю, что я почти получил его.
В моем setupController RecipesNewRoute у меня есть controller.set('styles', App.Style.find());
. Тогда, на мой взгляд, у меня есть {{view Ember.Select valueBinding='style' name='style' viewName='styleField' contentBinding='controller.styles' contentValuePath='content.id' contentLabelPath='content.name'}}
. Теперь моя проблема в том, что у меня есть поле выбора, за исключением того, что метка и значение установлены на <App.Style:ember407:100>
вместо идентификатора и имени.