Does Aurelia have virtual elements?

会有一股神秘感。 提交于 2019-12-06 04:10:17

问题


Knockout JS has the concept of virtual elements. These are "headless" elements which you can bind to that do not have an HTML element as a container. This allows you to bind arrays in a container that emits no outer HTML.

For example, in Knockout JS you can do something like:

<!-- ko foreach: items -->
  <li data-bind="text: $data"></li>
<!-- /ko -->

A series of li tags will be emitted without a parent element.

Does Aurelia offer something similar? I do see you can create custom elements in Aurelia which can be bound, but these custom elements are emitted to the DOM as HTML elements.

For example, in Aurelia you can do something like:

<foo repeat.for="item of items" foo.bind="item"></foo>

However, this will emit foo element tags. How do you accomplish something like this in Aurelia without the unwanted parent element tags?


回答1:


Thanks to James Thorpe for pointing me in the right direction. Aurelia added a @containerless attribute which you decorate your custom element class with. When you do it renders without the container.

Example:

import {customElement, containerless} from 'aurelia-framework';

@customElement('foo')
@containerless
export class Foo {
}


来源:https://stackoverflow.com/questions/32910490/does-aurelia-have-virtual-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!