通过获取从多个输入字段值附加阵列(文本框)

问题描述 投票:1回答:1

我使用奥里利亚框架。我有四个文本字段,在我的HTML视图一个按钮。

我创建了Array.Now我想,当用户填写文本框,然后值应该在我的对象数组的形式追加我宣布JSON类型的服务。

export class Std_service{
    rows:any;
    constructor(){
        this.rows = [{
            "name": "Aamir",
            "age": 20,
            "email": "[email protected]",
            "id" : 1
        }, {
            "name": "Adil",
            "age": 50,
            "email": "[email protected]",
            "id" : 1
        }, {
            "name": "Usman",
            "age": 45,
            "email": "[email protected]",
            "id" : 1
        }];
    }


}
arrays textbox aurelia
1个回答
3
投票

可以说你有是有界到你的输入字段变量。可以保存一个变量的ID(它没有用户的知识生成)

你可以添加一个功能到您的类与填充阵列和清除文本框的交易。

export class Std_service{
    id: number = 0;
    name: string = "";
    age: string = "";
    email: string = "";

    rows:any = [];
    addRow()
    {
        this.rows.push({"name": this.name,
            "age": this.age,
            "email": this.email,
            "id" : this.id});

        this.name = "";
        this.age = "";
        this.email = "";
        this.id++;
    }
}
<input type="text" value.bind="name">
<input type="text" value.bind="age">
<input type="text" value.bind="email">
<button click.delegate="addRow()">add user to array</button>
© www.soinside.com 2019 - 2024. All rights reserved.