【发布时间】:2019-05-24 13:54:27
【问题描述】:
我正在 aurelia 中开发一个名为 OnScreenKeyboardCustomAttribute 的自定义属性。工作完成后,我试图使用一个包含输入的自定义元素,我希望这个元素在该输入上工作。默认情况下,我在属性类中获取元素并期望它是输入或文本字段。
但是,在该自定义属性上,输入元素位于其他一些元素中。所以我认为下一步是进入元素并实现内部输入。这是可能的,但是当自定义属性具有无容器注释时,我在属性类中没有收到任何元素,而是收到<!--anchor-->。那么如何才能实现到内部元素呢?
自定义元素 - 视图模型
import {
containerless,
} from 'aurelia-framework';
@containerless()
export class CInputCustomAttribute {
}
自定义元素 - 视图
<template>
<div class.bind="paClass ? paClass : 'row margin_bottom'">
<div class.bind="labelClass ? labelClass : 'column_large_3 column_small_4'">
<label for="${id}" class="label_inline" class.bind="errors.length ? 'text_red' : '' "><span class="required_star"
if.bind="star">*</span>${label}</label>
</div>
<div class.bind="inputClass ? inputClass : 'column_large_9 column_small_8'">
<input id="${id}" placeholder="${placeholder}" class="input toggle_input" class.bind="errors.length ? 'validate-error' : '' "
value.bind="value" type="${type}" maxlength="${max ? max : 5000}" click.trigger="typeof runFunction=='function' ? runFunction():''">
<span class="message_red">
<template repeat.for="error of errors">
${error.error.message}<br>
</template>
</span>
</div>
<slot></slot>
</div>
</template>
自定义属性 - 视图模型
@inject(Element, BindingEngine)
export class PaOnScreenKeyboardCustomAttribute {
constructor(element, bindingEngine) {
this.element = element;
console.log(this.element);
}
用法
<c-input type="text" id="username" pa-on-screen-keyboard max="11">
console: <!--anchor-->
【问题讨论】:
-
再次提醒,这里将删除签名。此外,religious material 将被删除。我们这里有一个奇怪的有神论者,他们决心传教,但通常不受欢迎。请将其保存在您的博客、社交媒体或专门讨论有神论的网站上。
标签: element aurelia custom-attributes custom-element