[英]Ember.js stringtoclass
我正在尋找一種以類名作為字符串實例化新余燼對象的方法:
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!'
有可能做這樣的事情嗎?
我認為您無需在特殊情況下使用getter和setter。
您的解決方案是
Ember.get(window, "App.MyObject").create({hello:'Hello World!'});
但是我認為一個簡單的例子是:
var className = "MyObject";
App[className].create({hello:'Hello World!'});
將工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.