我正在尝试为 AngularJS 应用程序创建一个丰富的数据模型,我希望我的模型继承自Array<BaseModel>
. 我还没有找到一种方法来做到这一点(有信心)。
在伪代码中,这将类似于:
// NOT REAL CODE. DOES NOT WORK
class BaseModel {}
class Person extends BaseModel {}
class People extends Array<Person> {
constructor(private promise:Promise) { }
$unwrap(promise) {
promise.then((response) => {
response.data.map((person) => {
this.push(new Person(person));
});
});
}
static $load() {
/* do some ajaxy thing and unwrap the promise right onto the
the new instance of this rich model */
return new People(promise);
}
}
我想要这样的原因是现在我可以直接将此模型绑定到我的视图并即时获取更新。
关于从 Array 扩展的任何想法?