0
我想解決如何做一個startsWith?這是一個自定義元素,它需要驗證字符串以「\」Aurelia驗證匹配
<template>
<input disabled.bind="readonly" type="text" class="form-control" value.bind="value">
</template>
import {customElement, bindable, inject, bindingMode} from 'aurelia-framework';
import {activationStrategy} from 'aurelia-router';
import $ from 'jquery';
import {Validation} from 'aurelia-validation';
@customElement('url')
@bindable({name: 'value', attribute: 'value', defaultValue: '', defaultBindingMode: bindingMode.twoWay})
@bindable({name: 'readonly', attribute: 'disabled', defaultValue: false, defaultBindingMode: bindingMode.oneWay})
@inject(Element, Validation)
export class Url {
constructor(element, validation) {
this.element = element;
this.validation = validation.on(this)
.ensure(this.element)
.isNotEmpty()
.containsNoSpaces()
.matches('/^[\].*/');
}
bind(){
$('.input', this.element).val(this.value);
if(this.readonly){
$('.input', this.element).attr('readonly', 'readonly');
}
}
}
我已經看了http://aurelia.io/validation/#/logical-operators,我覺得我這樣做是正確啓動,但它拋出一個錯誤:內部誤差:類型錯誤: path.split不是函數
你不需要導入元素或jQuery。你是否正確插入了「aurelia-validation」?您應該閱讀aurelia驗證入門指南https://github.com/aurelia/validation/blob/master/doc/Intro.md#installation –