自定義元素允許您在使用自定義標記時通過<content></content>
選擇器訪問自定義標記的內部html,以及將內容拉入該視圖的某些規範。在類中訪問內容選擇器的自定義元素
我希望能夠訪問我的班級中的這些數據,而不包裝標籤。
我嘗試了以下內容:<content ref="content"></content>
和this.content
引用它繼databinding ref attribute戰略羅布艾森伯格看好,但在元素生命週期的每個階段console.log(this.content)
產量undefined
。
我想到的解決方法是將<content>
標記放置在另一個元素中,使用jquery將其拖出文本並緩存,然後通過ref
屬性移除該元素,但這看起來不雅觀。
如何在與自定義元素關聯的es6類中訪問這些數據?
示例方案:
一些-view.html
<template>
<customelement>Hello World</customelement>
<template>
customelement.html
<template>
Something, but not a content tag
</template>
customelement.js
export class CustomElement {
get foobar() {
//Somehow ascertain "Hello World" without displaying it in customelement
}
}
在此示例中,可以假定自定義元素是全局包含的。
'@ processContent'裝飾器能爲你工作嗎? http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/cheat-sheet/9 不確定我是否完全瞭解您的方案 - 請考慮添加一個示例,顯示您的自定義元素的預期用法。 –
@JeremyDanyow看着文檔,我不知道如何繼續以及過程函數如何給出這些參數。我已經用一個最小的例子更新了我的問題,希望這可以清除它 – David