I'I’我试图获取表格中的信息,但没有成功

I'm trying to get the information inside ng-repeat to submit the form but fail

本文关键字:信息 成功 获取 表格      更新时间:2023-09-26

查看

<div ng-controller="AttCtrl">
        <div ng-repeat="type in types">
            <h5>@{{type.name}}</h5>
            <input type="hidden" name="@{{'type_'+$index}}" value="@{{type.name}}">
            <div ng-repeat="att in type.data">
                <a><i class="fa fa-times" ng-click="delete(type.name,att)"></i></a> @{{att}} <br>
                <input type="hidden" name="@{{'att_'+$parent.$index+$index}}" value="@{{att}}">
            </div>
            <input type="text" ng-model="new_att" ng-enter="add_att(type.name,new_att); new_att='';">
            <a><i class="fa fa-plus-circle fa-lg" ng-click="add_att(type.name,new_att); new_att='';"></i></a>
            <br><br>
        </div>
        <a ng-click="add_type()">new property</a>
        <hr>
    </div>

一切似乎都很好。我可以随时添加和删除所有内容,但当我提交时,ng repeat中没有任何内容被存储(其余内容都可以(。

Laravel控制器

        //@store
        $product = new Product;
        //a lot of stuff here
        $product->save();
        for ($i=0; Input::has('type_'.$i); $i++) { 
            for ($j=0; Input::has('att_'.$i.$j); $j++) { 
                $att = new Attribute;
                $att->name = Input::get('att_'.$i.$j);
                $att->type = Input::get('type_'.$i);
                $att->product_id = $product->id;
                $att->save();
            }
        }

提前感谢D

Ng repeat为它的每个重复创建一个新的作用域,因此如果您想正确存储数据,您需要指向$parent作用域,以便将数据存储在控制器作用域中。