在Ember.js中,如何使用父模型的函数
我有两种型号:在Ember.js中,如何使用父模型的函数,ember.js,ember-data,Ember.js,Ember Data,我有两种型号: Parent = Ember.Model.extend({ hello: function() { console.log("parent says hello"); }, world: function() { console.log("parent says world"); } }); Child = Ember.Model.extend(Parent, { hello: function() { console.log("chi
Parent = Ember.Model.extend({
hello: function() {
console.log("parent says hello");
},
world: function() {
console.log("parent says world");
}
});
Child = Ember.Model.extend(Parent, {
hello: function() {
console.log("child says hello");
// how do I call Parent.hello here?
// how do I call Parent.world here?
}
});
我想从Child.hello函数中调用Parent.hello和Parent.world函数
我该怎么做呢?在Child.hello函数中是否可以使用super方法,或者只使用bind并引用父模型类?您可以使用它。\u super调用父方法。《灰烬指南》对此进行了简要介绍
要调用未被重写的方法,只需执行以下操作
您可以在这里看到它的一个示例:您可以使用它。\u super调用父方法。《灰烬指南》对此进行了简要介绍
要调用未被重写的方法,只需执行以下操作
您可以在这里看到一个示例:没什么特别的,只是:
我怎么打电话给家长?喂
这个
我在这里怎么称呼Parent.world
这个世界
没什么特别的,只是:
我怎么打电话给家长?喂
这个
我在这里怎么称呼Parent.world
这个世界
这并没有真正回答我的问题,我想获取我从中继承的模型并访问其属性。基本上是将我的子类转换为父类。老实说,它回答了您最初的问题,即从Child调用parent.hello。hello:无论如何,没有被重写的方法应该只能由this.world调用。这并没有真正回答我的问题,我想获取我从中继承的模型并访问其属性。基本上是将我的子类转换为父类。老实说,它回答了您最初的问题,即从Child调用parent.hello。hello:无论如何,没有被重写的方法应该只能由this.world调用。如果我的孩子也覆盖了世界属性,而我不能再这样做。世界?你仍然可以从孩子调用this.super,它覆盖了世界中的世界方法,所以你仍然可以这样做。世界,但从另一个方法。这只是设计。似乎您真的想将实例强制转换为其父类型,但这不是C::D关于我的孩子是否也覆盖了world属性,而我不能再这样做了。world?您仍然可以调用this.super from Child,它覆盖了world in world方法中的world,所以您仍然可以这样做。world,但可以从另一个方法。这只是设计。似乎您真的想将实例强制转换为其父类型,但它不是C:D