EmberJS控制器之间的绑定内容

dre*_*ovi 8 javascript model-view-controller binding ember.js

我目前正在使用两种数据模型,其中Foo具有Bars类型的"toMany"属性.我现在正在尝试创建两个选择框,当选择第一个填充Foo的时,它仅在第二个列表中精炼与该foo相关联的条.

JSFiddle这里:http: //jsfiddle.net/drew/6jLCy/

代码如下,但肯定不起作用.它确实为第一个设置SelectBox值,但不会使用相应的条形值标题填充第二个值.

App = Em.Application.create();

App.store = DS.Store.create({
  revision: 7,
  adapter: DS.fixtureAdapter
});

/**************************
* Models
**************************/

App.Foo = DS.Model.extend({
    bars: DS.hasMany('App.Bar'),
    title: DS.attr('string')
});
App.Bar = DS.Model.extend({
    foos: DS.hasMany('App.Foo'),
    title: DS.attr('string')
});


/**************************
* Fixtures
**************************/

App.Foo.FIXTURES = [
    {
        id: 0,
        title: 'Footitle 1',
        bars: [0,1]
    },
    {
        id: 1,
        title: 'Footitle 2',
        bars: [0,1,2]
    }
];

App.Bar.FIXTURES = [
    {
        id: 0,
        title: 'Bartitle 1',

    },{
        id: 1,
        title: 'Bartitle 2'
    },{
        id: 2,
        title: 'Bartitle 3'
    }
];


/**************************
* Views
**************************/

App.SetFooField = Em.Select.extend({
    contentBinding: 'App.fooController',
    valueBinding: 'content.selected',
    optionLabelPath: 'content.title'
});

App.SetBarField = Em.Select.extend({
    contentBinding: 'App.barController',
    valueBinding: 'content.selected',
    optionLabelPath: 'content.title'
});

/**************************
* Controllers
**************************/

App.fooController = Em.ArrayController.create({
    content: App.store.findAll(App.Foo)
});

App.barController = Em.ArrayController.create({
    contentBinding: 'App.fooController.selected.bars'
});?
Run Code Online (Sandbox Code Playgroud)

标记为html:

<script type="text/x-handlebars">

    {{view App.SetFooField}}
    {{view App.SetBarField}}

</script>?
Run Code Online (Sandbox Code Playgroud)

dre*_*ovi 1

天啊。经过多天的疯狂之后,事实证明这完全是最新 ember-data 中的一个错误。在装置中,所有 id 都必须是字符串。只是。清楚的。坚果。

/**************************
* Fixtures
**************************/

App.Foo.FIXTURES = [
    {
        id: '0',
        title: 'Footitle 1',
        bars: ['0','1']
    },
    {
        id: '1',
        title: 'Footitle 2',
        bars: ['0','1','2']
    }
];

App.Bar.FIXTURES = [
    {
        id: '0',
        title: 'Bartitle 1',

    },{
        id: '1',
        title: 'Bartitle 2'
    },{
        id: '2',
        title: 'Bartitle 3'
    }
];
Run Code Online (Sandbox Code Playgroud)

无法使用 ember.js 和 ember-data 获取嵌入的对象属性

非常感谢@dgeb 回答这个问题。

jsfiddle 相应更新。

http://jsfiddle.net/drew/6jLCy/