首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aurelia-对话框使用附加-焦点自定义元素

Aurelia-对话框使用附加-焦点自定义元素
EN

Stack Overflow用户
提问于 2016-11-17 18:39:22
回答 1查看 502关注 0票数 0

我试图将attach-focus="true"传递给自定义元素的内部元素之一,以便当aurelia-对话框打开时,正确的元素将收到焦点。

自定义元素: enum-list.html

代码语言:javascript
复制
<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

代码语言:javascript
复制
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:

代码语言:javascript
复制
<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):

代码语言:javascript
复制
this.dialogService.open({ viewModel: EditLocale, model: this.record, lock: true }).then(response => {

如果我从edit-locale.js中的附加焦点和自定义元素中删除破折号,那么模态对话框将很好地加载。但是用破折号,我得到了一个错误:Uncaught SyntaxError: Unexpected token import。我认为这是干扰,但我不知道如何解决它。

我的首选是修复它,以便自定义控件的实例化具有标准参数attach-focus="true" (带有破折号),以便它与常规元素(如输入和选择)保持一致。

EN

回答 1

Stack Overflow用户

发布于 2016-11-18 05:48:28

关于错误的来源,您是正确的,不能有包含破折号的property-name。因为它读起来像property - name

aurelia (链接到文档,搜索破折号)中有一个惯例,可以将属性和元素名称从破折号符号映射到camelCase符号,因此如果在模型中将绑定属性命名为@bindable attachFocus --您将能够在视图中使用它作为附加-焦点. be =“true”。

还请确保在您的视图中<require>您的自定义元素/属性,或者在配置aurelia时使它们全局可用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40662613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档