两个Ember.JS ArrayController?

两个Ember.JS ArrayController?,ember.js,Ember.js,我正在构建的一个Ember.JS应用程序有点问题: App.userController = Ember.ArrayController.create({ content: [], init: function() { this.set('content', []); this.refresh(); }, refresh: function() {

我正在构建的一个Ember.JS应用程序有点问题:

    App.userController = Ember.ArrayController.create({
        content: [],

        init: function() {
            this.set('content', []);
            this.refresh();
        },

        refresh: function() {
            //Refresh Action
        }
    });

    App.supplierController = Ember.ArrayController.create({
        content: [],

        init: function() {
            this.set('content', []);
            this.refresh();
        },

        refresh: function() {
            //Refresh Action
        }
    });

    <h1>Users</h1>
    {{#each user in App.userController}}
        {{user.name}} - {{user.age}}
    {{/each}}

    <h1>Suppliers</h1>
    {{#each supplier in App.supplierController}}
        {{supplier.name}} - {{supplier.revenue}}
    {{/each}}
应在何时显示此信息:

Users
-----------
User 1 - 30 
User 2 - 25

Suppliers
-----------
Supplier 1 - £100

你的代码看起来不错。拥有两个
ArrayController
实例没有什么错。我根据您的问题制作了一个jsbin,并在正确的位置查看用户/供应商。在这里查看:

因为您的示例没有显示数据是如何加载的,所以我实现了refresh()方法来根据您的预期输出填充用户/供应商列表:

App = Ember.Application.create({});

App.userController = Ember.ArrayController.create({
    content: [],

    init: function() {
        this.set('content', []);
        this.refresh();
    },

    refresh: function() {
      this.addObject({name: 'u 1', age: 22});
      this.addObject({name: 'u 2', age: 35});
    }
});

App.supplierController = Ember.ArrayController.create({
    content: [],

    init: function() {
        this.set('content', []);
        this.refresh();
    },

    refresh: function() {
        //Refresh Action
      this.addObject({name: 'supplier 1', revenue: 200});
    }
});

此外,您可能希望使用Ember.ArrayController.extend()而不是Ember.ArrayController.create();非常感谢。我发现了问题。我有一个名为
me
的变量,它是在refresh中声明的。它没有正确声明,所以我猜这两个控制器引用了相同的
me
,从而将一个对象推到了同一个对象上。
App = Ember.Application.create({});

App.userController = Ember.ArrayController.create({
    content: [],

    init: function() {
        this.set('content', []);
        this.refresh();
    },

    refresh: function() {
      this.addObject({name: 'u 1', age: 22});
      this.addObject({name: 'u 2', age: 35});
    }
});

App.supplierController = Ember.ArrayController.create({
    content: [],

    init: function() {
        this.set('content', []);
        this.refresh();
    },

    refresh: function() {
        //Refresh Action
      this.addObject({name: 'supplier 1', revenue: 200});
    }
});