typescript - Aurelia'da çalışma zamanında view-model'e çocuk ekleme
component.html için bu şekilde görünen bir şablonum var
<template>
<div>${someBoundProperty}</div>
<slot></slot>
</template>
Şu şekilde app.html içinde kullanılmalıdır:
<div>
<component some-bound-property="text here">
<component some-bound-property="more text"></component>
<component some-bound-property="and more text"></component>
</component>
</div>
ve işte component.ts
export class ComponentCustomElement {
@bindable someBoundProperty: string;
@children('component') subComponents: ComponentCustomeElement[] = []
}
Şu ana kadar her şey beklendiği gibi çalışıyor. Aurelia'da component.ts içindeki aşağıdaki gibi view-model'imde çalışırken dizime çocuk eklemenin bir yolu var mı?
attached() {
var newItem = new ComponentCustomElement();
newItem.someBoundProperty = "my custom text";
this.subComponents.push(newItem);
}
Elbette, diziye bir öğe eklemek görsel tarafta hiçbir şey üretmez. Görünümü ve yeni görünüm modelini oluşturup bunu işlemek için Aurelia'ya göndermenin bir yolu var mı?