【发布时间】:2016-11-17 18:39:22
【问题描述】:
我正在尝试将attach-focus="true" 传递给自定义元素的内部元素之一,以便在打开 aurelia-dialog 时正确的元素将获得焦点。
自定义元素: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;
}
对话框模板:edit-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"(带有破折号),以便与 INPUT 和 SELECT 等普通元素保持一致。
【问题讨论】:
标签: javascript aurelia