[英]Ember.js stringtoclass
I'm searching a way to instatiate a new ember object with the classname as a string: 我正在寻找一种以类名作为字符串实例化新余烬对象的方法:
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!'
Is there a possibility to do something like this? 有可能做这样的事情吗?
I think you dont need to use getters and setters in your special case. 我认为您无需在特殊情况下使用getter和setter。
Your solution was 您的解决方案是
Ember.get(window, "App.MyObject").create({hello:'Hello World!'});
But I think a simple one like: 但是我认为一个简单的例子是:
var className = "MyObject";
App[className].create({hello:'Hello World!'});
will work. 将工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.