0

クラス名を文字列として使用して、新しいemberオブジェクトをインスタンス化する方法を探しています。

App.MyObject = Ember.Object.extend({hello:'hello'});
//Try to do something like this.
App.myObject = Ember.create("App.MyObject", {hello:'Hello World!'});
console.log(App.myObject.hello); //productes 'Hello World!'

このようなことをする可能性はありますか?

4

1 に答える 1

0

特別な場合には、ゲッターやセッターを使用する必要はないと思います。

あなたの解決策は

Ember.get(window, "App.MyObject").create({hello:'Hello World!'});

しかし、私は次のような単純なものだと思います。

var className = "MyObject";
App[className].create({hello:'Hello World!'});

動作します。

于 2012-09-03T22:38:50.127 に答える