自定义属性没有绑定绑定属性

时间:2015-07-21 13:50:58

标签: aurelia

也许有人可以帮我解决这个问题。

我似乎无法将回调绑定到customAttribute。 这里有一些代码

import {inject, customAttribute, bindable} from 'aurelia-framework';
import 'typeahead';

@customAttribute('typeahead')
@inject(Element)
export class Typeahead {
    @bindable minLength = 0;
    @bindable highlight = true;
    @bindable substringMatcher = null;

    constructor(element) {
        this.element = element;
    }

    attached() {
        var self = this;
        $(self.element).typeahead({
            hint: true,
            highlight: self.highlight,
            minLength: self.minLength
        },
        {
            name: 'query',
            source: (query) =>
            {
                console.log(self.substringMatcher);
                if(self.substringMatcher){
                    self.substringMatcher(query);
                }
            }
        });
    }

}

我一直在尝试以多种方式分配substringMatcher可绑定回调,但该属性始终为null

<input typeahead="substringMatcher.bind: search" class="form-control typeahead">
<input typeahead="substringMatcher: search" class="form-control typeahead">
<input typeahead="substringMatcher: this.search" class="form-control typeahead">

任何想法为什么?

1 个答案:

答案 0 :(得分:3)

属性错误的情况......

这有效: <input typeahead="substring-matcher: search" class="form-control typeahead">