gpt4 book ai didi

javascript - Ember 绑定(bind) : binding a property to its a child's property

转载 作者:行者123 更新时间:2023-11-30 18:15:17 25 4
gpt4 key购买 nike

我有一个有两个 subview 的 Ember.View.ParentView。其中之一是 ContainerView。 ParentView 的另一个 subview 需要访问 ContainerView 的 subview 。

在 ContainerView 中,我尝试使用:

 this.get('parentView').set('foo', this.get('childViews') )

希望这会将 ParentView 中的属性设置为 childView View 的数组。但是,在ParentView的第二个childView中,调用:

 foo = this.get('parentView').get('foo')

返回类数组而不是实例。所以我现在正在尝试使用绑定(bind)。如何创建属性到类子属性的绑定(bind)?

最佳答案

使用 viewName 属性在父实例中设置 childViews 实例的名称(参见相关提交 here):

App.MyParentView = Ember.View.extend({

containerViewChilds: 'fooContainer.childViews',

aContainerView: Ember.ContainerView.extend({
// ...
}),

anotherView: Ember.View.extend({
containerViewChildsBinding: 'parentView.containerViewChilds'
// ...
})
});

App.MyParentView 模板:

{{view view.aContainerView viewName="fooContainer"}}

{{view view.anotherView}}

关于javascript - Ember 绑定(bind) : binding a property to its a child's property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13423591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com