angularjs2版本创建一个数组,将数组里面的内容通过数据绑定的形式循环到table表单中

 源代码
组件里面的 template代码部分
<table id="table" class="table table-bordered table-responsive table-striped">
    <tr><th class="col-lg-2">货道号</th><th class="col-lg-4">容量</th><th class="col-lg-4">货道位置</th><th class="col-lg-2">操作</th></tr>
    <tr  *ngFor="let item of shop;let i = index" >
        <td><input type="text" name="id"  value="{{item.id}}"  disabled ><input class="cou-input" type="text" name="id"  placeholder="{{item.id}}" ></td>
        <td><input type="text" name="num"  value="{{item.num}}" disabled><input class="cou-input" type="text" name="num"  placeholder="{{item.num}}"  ></td>
        <td><input type="text" name="dress"  value="{{item.dress}}" disabled><input class="cou-input" type="text" name="dress"  placeholder="{{item.dress}}"  ></td>
        <td>
            <i class="iconfont">&#xe616;</i> <button (click)="getData($event)">编辑</button>
        </td>
    </tr>
</table>
export class ModeldetailComponent implements OnInit {
    flag = true;

    shop= [
        {id: "000", num: 10, dress: "1排"},
        {id: "001", num: 10, dress: "1排"},
        {id: "002", num: 10, dress: "1排"},
        {id: "003", num: 10, dress: "1排"},
        {id: "004", num: 10, dress: "1排"},
        {id: "005", num: 10, dress: "1排"},
        {id: "006", num: 10, dress: "1排"},
        {id: "007", num: 10, dress: "1排"},
        {id: "008", num: 10, dress: "1排"},
        {id: "009", num: 10, dress: "1排"},
        {id: "010", num: 10, dress: "1排"}
    ];
    getData(event){
        var otr=event.path[2];
        var len=event.path[2].children.length;

        if(this.flag){
            var i=0;
            while (i<(len-1)){
                otr.children[i].children[0].style.display="none";
                otr.children[i].children[1].style.display="inline";
                i++;
            }
            if (i==(len-1)){
                otr.children[i].children[0].innerHTML="&#xe615;"
                otr.children[i].children[1].innerHTML="保存";
            }
            this.flag=false;
        }else {
            var i=0;
            while (i<(len-1)){
                otr.children[i].children[0].style.display="inline";
                otr.children[i].children[1].style.display="none";
                i++;
            }
            if (i==(len-1)){
                otr.children[i].children[0].innerHTML="&#xe616;"
                otr.children[i].children[1].innerHTML="编辑";
            }
            this.flag=true;
        }
 }  

运行之后的效果图


点击编辑之后的效果图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值