私はaureliaフレームワークが初めてです。私はインライン編集でテキスト入力のリストを作成しようとしています。すべての入力はデフォルトで無効にする必要があります。編集ボタンをクリックすると、disbaled
属性を削除して編集できるようになります。ビュー内の配列の要素を結合する
マイwelcome.js:
import {inject} from 'aurelia-framework';
@inject(HttpClient)
export class Welcome {
heading = 'Welcome';
inputs_list = [
{
'id': 1,
'text': 'example one',
'edit': false
},
{
'id': 2,
'text': 'example two',
'edit': false
},
];
editInput(evt){
let input = this.inputs_list.find(input => input.id === id);
input.edit = true;
}
}
マイビューファイルのwelcome.html:
<template>
${heading}
<ul>
<li repeat.for="input of inputs_list">
<input ${input.edit ? '' : 'disabled'} type="text" value="${input.text}" class="inputs"/>
<input type="button" click.delegate="editInput(input.id)" value="edit" />
</li>
</ul>
</template>
そして、私は警告し取得しています:
WARN [templating-binding] Unknown binding command. Object {defaultBindingMode: null, attrName: "${input", attrValue: "", command: "edit", expression: null}
私はすでに解決策を発見しましたeditInput
メソッドを変更し、$event
をパラメータとして渡します:
editInput(evt){
let inputs = evt.target.parentNode.getElementsByClassName('inputs');
Array.from(inputs).forEach(input => input.removeAttribute('disabled'));
}
これは機能しますが、これを達成するための適切な方法は何ですか?
ありがとう! – pa7ryk