Ember.在使用路由器的应用程序中选择contentBinding

wma*_*but 2 javascript ember.js ember-old-router

我有一个使用Ember.Router结构的Ember.js应用程序.

我的app结构看起来像

window.App = Ember.Application.create {
    #Truncated idea of app, not including application controller or any of that
    MainController = Ember.Controller.extend()
    MainView = Ember.View.extend
        templateName: 'main-template'
Run Code Online (Sandbox Code Playgroud)

所以控制器和视图中扩展,而不是建立在应用程序的创建.然后有连接出口的路线

Router: Ember.Router.extend
    root: Ember.Route.extend
        main: Ember.Route.extned
            route: '/'
            connectOutlets: (router, event) ->
                router.get('applicationController').connectOutlet('main')
Run Code Online (Sandbox Code Playgroud)

我需要将<select>标记绑定到一组值.Ember.Select看起来这是一个很好的方法,所以我添加一个控制器和视图扩展为选择

MySelectController: Ember.ArrayController.extend
    contents: [{id:1,title:'test'},{id:2,title:'test2'}]
MySelectView: Ember.Select.extend
    contentBinding: this.get('controller')
    contentValuePath: 'id'
    contentLabelPath: 'title'
Run Code Online (Sandbox Code Playgroud)

这不起作用.this.get('controller')当我尝试在视图中包含时,我收到错误{{#view App.MySelectView}}

我该怎么做?

sly*_*7_7 6

这是一个如何实现这个的例子:jsfiddle

把手模板:

<script type="text/x-handlebars" data-template-name="application">
  <header>
    <h1>Ember Router Sample</h1>
  </header>
  {{outlet}}
</script>

<script type="text/x-handlebars" data-template-name="myForm">
  {{view view.mySelectView 
    selectionBinding="controller.selected" 
    contentBinding="view.controller.content.persons"
  }}
  {{view Ember.TextField valueBinding="controller.selected.name"}}
</script>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

App = Ember.Application.create();

App.ApplicationController = Em.Controller.extend();
App.ApplicationView = Em.View.extend({
  templateName: 'application'
});

App.MySelectController = Em.ArrayController.extend();

App.MyFormController = Em.Controller.extend({
  selected: null,
});

App.MyFormView = Ember.View.extend({
  templateName: 'myForm',
  mySelectView: Em.Select.extend({
    optionLabelPath: 'content.name',
    optionValuePath: 'content.id'
  })
});

App.Router = Em.Router.extend({

  root: Em.Route.extend({

    index: Em.Route.extend({
      route: '/',
      connectOutlets: function(router, context) {
        router.get('applicationController').connectOutlet({
          name: 'myForm',
          context: Ember.Object.create({
              persons: [{id:0, name: "Wayne"}, {id: 1, name: "Gart"}]
          })
        });
      }
    })
  })
});
App.initialize();
Run Code Online (Sandbox Code Playgroud)