2

私は残り火が初めてで、小さな配列をコントローラーにロードしようとしています。問題は、cardController で定義した addCard 関数が表示されず、「object function() has no method 'addCard'」というエラーが表示されることです。私は何を間違っていますか?私は以下を使用しています:

ハンドルバー-1.0.0-rc.3.js、
ember-1.0.0-rc.3.js、
ember-data.js

これが私のコードです:

App = Ember.Application.create({
    ready: function(){
        //Populate content[] in cardController
        App.GetCards();
    }
});

App.GetCards = function(){
    card1 = App.Card.create({
                id: 0,
                title: 'Alabama',
                desc: 'Montgomery'
            });

    App.cardsController.addCard(card1);
};

App.Card = Ember.Object.extend({
    id: null,
    title: null,
    desc: null,
    current: true
});

App.cardsController = Ember.ArrayController.extend({
    content: [],

    //Property that adds an item to content
    addCard: function(item){
        this.addObject(item);
    }
});
4

2 に答える 2

0

私は、次のコードを含む古い Ember.js チュートリアルに取り組んでいました。

App.recentUsersController = Ember.ArrayController.create({
    content: [],
    addUser: function(name) {
        if( this.contains(name) ) this.removeObject(name);
        this.pushObject(name);
    },
    removeUser: function(view) {
        this.removeObject(view.context);
    },
    searchAgain: function(view) {
        App.tweetsController.set('username', view.context);
        App.tweetsController.loadTweets();
    },
    reverse: function(){
        return this.toArray().reverse();
    }.property('@each')
});

エラーが発生し続けましたError: Assertion Failed: Ember.Object.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().

さて、私は非常に説明的な(そして役立つ)エラーメッセージを取り、それをチェーンについて知っていることと組み合わせて、これを得ました:

App.recentUsersController = Ember.ArrayController.extend({
    content: [],
    addUser: function(name) {
        if( this.contains(name) ) this.removeObject(name);
        this.pushObject(name);
    },
    removeUser: function(view) {
        this.removeObject(view.context);
    },
    searchAgain: function(view) {
        App.tweetsController.set('username', view.context);
        App.tweetsController.loadTweets();
    },
    reverse: function(){
        return this.toArray().reverse();
    }.property('@each')
}).create({});

最初に拡張してから作成します。私のために働き、他の誰かが古いバージョンのEmberでこの問題に遭遇した場合に備えて、そこに捨てたいと思いました.

于 2014-04-23T19:03:06.303 に答える