заполнение поля выбора с использованием представления выбора emberjs

Я работаю над игрушечным приложением, чтобы изучить 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> вместо идентификатора и имени.


person spullen    schedule 16.03.2013    source источник


Ответы (1)


Ember Select использует optionValuePath и optionLabelPath, и похоже, что вы используете contentValuePath и contentLabelPath.

Пример jsFiddle здесь: http://jsfiddle.net/nrionfx/BJwLR/2/

Из документации ember: http://emberjs.com/api/classes/Ember.Select.html

{{view Ember.Select
       contentBinding="App.programmers"
       optionValuePath="content.id"
       optionLabelPath="content.firstName"}}
person nrion    schedule 16.03.2013
comment
Ах, спасибо, похоже, я был на правильном пути и только что перепутал свое соглашение об именах. - person spullen; 16.03.2013