我试图将attach-focus="true"传递给自定义元素的内部元素之一,以便当aurelia-对话框打开时,正确的元素将收到焦点。
自定义元素: enum-list.html
<template>
<label class="control-label">${label} DEBUG: ${attach-focus}</label>
<select class="form-control" value.bind="value" attach-focus.bind="attach-focus">
<option if.bind="data" repeat.for="code of data | keys" value="${code}">${data[code]}</option>
</select>
</template>自定义元素: enum-list.js
import { bindable, bindingMode } from 'aurelia-framework';
export class EnumListCustomElement {
@bindable label;
@bindable data;
@bindable attach-focus; // <-- Maybe the source of the error?
@bindable({ defaultBindingMode: bindingMode.twoWay }) value;
}对话框模板:Edt-locale.html:
<template>
<ai-dialog>
<ai-dialog-header class="modal-header modal-header-success">
<h4 class="modal-title">Edit Locale</h4>
</ai-dialog-header>
<ai-dialog-body>
<form>
<enum-list attach-focus="true" label="Language" data.bind="core.enums.SystemLanguage" value.bind="sch_lang"></enum-list>
<enum-list label="Currency" data.bind="core.enums.CurrencyCode" value.bind="sch_currency"></enum-list>
</form>
</ai-dialog-body>
<ai-dialog-footer>
<button type="button" click.trigger="dialogController.cancel()">Cancel</button>
<button type="button" click.delegate="dialogController.ok()">Save</button>
</ai-dialog-footer>
</ai-dialog>
</template>实例化(来自我的VM js):
this.dialogService.open({ viewModel: EditLocale, model: this.record, lock: true }).then(response => {如果我从edit-locale.js中的附加焦点和自定义元素中删除破折号,那么模态对话框将很好地加载。但是用破折号,我得到了一个错误:Uncaught SyntaxError: Unexpected token import。我认为这是干扰,但我不知道如何解决它。
我的首选是修复它,以便自定义控件的实例化具有标准参数attach-focus="true" (带有破折号),以便它与常规元素(如输入和选择)保持一致。
发布于 2016-11-18 05:48:28
关于错误的来源,您是正确的,不能有包含破折号的property-name。因为它读起来像property - name。
aurelia (链接到文档,搜索破折号)中有一个惯例,可以将属性和元素名称从破折号符号映射到camelCase符号,因此如果在模型中将绑定属性命名为@bindable attachFocus --您将能够在视图中使用它作为附加-焦点. be =“true”。
还请确保在您的视图中<require>您的自定义元素/属性,或者在配置aurelia时使它们全局可用。
https://stackoverflow.com/questions/40662613
复制相似问题