angular 4 ---------------添加和编辑功能

add() {
    this.tittle = '添加';
    // 遍历headers每个值
    this.headers.map( v => {
        v['val'] = '';
    });
    this.show_form = true;
    this.show_table = false;
}
edit(index) {
    // 将数据表的数据赋值给headers对应的值
     // index是个对象  如:index={i;2}
    this.tittle = '编辑';
    const i = index['i'];
    console.log('edit', this.data);
    this.headers.map(d => {
        console.log('-----------',d)
        switch (d.type) {
            case 'input':
                d.val = this.data[i][d.key];
                break;
            case 'select':
                d.val = this.data[i][d.key];
                break;
            case 'select-line':
                d.val = '';
                break;
            case 'fuzzy_select':
                d.val = this.data[i]['role'];
                console.log('========', d.val);
                break;
            default:
                d.val = this.data[i][d.key];
        }

        this.show_form = true;
        this.show_table = false;
    });
}

猜你喜欢

转载自blog.csdn.net/qq_38643776/article/details/80962534