如何从Aurelia中的自定义元素中设置父属性?

如何从Aurelia中的自定义元素中设置父属性?,aurelia,Aurelia,几天前我问了这个问题 现在,我需要能够在父元素(create.js)中重用来自我的自定义元素(my custom.js)的allSelectableValues 我在create.js上有一个自定义值转换器,它包含一些ID,我需要通过循环遍历当前获取并驻留在自定义元素中的元素数组来显示这些ID的名称 **create.html** <td>${d.SomeID | allSelectableValuesMapping}</td> 在理想的世界里,我希望这样的事情能够奏效

几天前我问了这个问题

现在,我需要能够在父元素(create.js)中重用来自我的自定义元素(my custom.js)的
allSelectableValues

我在create.js上有一个自定义值转换器,它包含一些ID,我需要通过循环遍历当前获取并驻留在自定义元素中的元素数组来显示这些ID的名称

**create.html**
<td>${d.SomeID | allSelectableValuesMapping}</td>
在理想的世界里,我希望这样的事情能够奏效:

**my-custom.js**
async attached() {
    this.allSelectableValues= await await this.myService.getAllValues();
    this.parent.allSelectableValues = this.allSelectableValues;
}
但是我的自定义元素不知道需要它的父元素

有人知道如何从自定义元素中将父元素的allSelectableValues设置为自定义元素的allSelectableValues吗?或者,在保持双向数据绑定自定义元素的同时,还有其他更好的方法来实现它吗?

类似的东西

请特别注意
@customElement('customElement')
导出类customElement
代码行上方的声明符

自定义图元视图模型 自定义元素HTML 父HTML


DOM中区分大小写的元素名称是什么?几乎:$(item.someProperty}应该是$(item.someProperty},不带camelcasing:-)谢谢!我还有最后一个问题。关于上面示例中的值转换器。我如何发送arrItems(我们刚刚得到了一个消息)与我的示例中的值一起?我得到的arrItems是未定义的Charleh我记不清确切的代码了。它更多的是伪代码。@Dac0d3r我不是专家,但值转换器更多的是源数据的临时前端转换(即,它不修改源数据)。您不能将值转换器也应用于自定义元素,或者应用于需要的任何位置吗?
**my-custom.js**
async attached() {
    this.allSelectableValues= await await this.myService.getAllValues();
    this.parent.allSelectableValues = this.allSelectableValues;
}
import {inject} from 'aurelia-framework';
import {customElement} from 'aurelia-framework';
import {bindable} from 'aurelia-framework';

@customElement('CustomElement')
export class CustomElement {
    @bindable arrItems
}
<template>
    <div repeat.for="item of arrItems">$(item.someProperty}</div>
</template>
export class ParentViewModel {
    parentArrItems = [];
}
<template>
    <require from="customelement"></require>

    <CustomElement arrItems.bind="parentArrItems"></CustomElement>
</template>