Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Select2函数在动态形式下不起作用_Javascript_Angularjs_Jquery Select2 - Fatal编程技术网

Javascript Select2函数在动态形式下不起作用

Javascript Select2函数在动态形式下不起作用,javascript,angularjs,jquery-select2,Javascript,Angularjs,Jquery Select2,大家好,我正在从事angular js项目。但这里有一个小问题,我使用动态表单搜索多个字段,并使用select2功能进行搜索,但第一次它工作,然后在创建新字段后,它不用于搜索,你能帮助我吗 这是我制作动态场的控制器代码 $scope.choices = [{id: 1,purchaser_account:'',price:0,weight:0}]; $scope.addNewChoice = function() { var newItemNo = $scope.choices.length+1

大家好,我正在从事angular js项目。但这里有一个小问题,我使用动态表单搜索多个字段,并使用select2功能进行搜索,但第一次它工作,然后在创建新字段后,它不用于搜索,你能帮助我吗

这是我制作动态场的控制器代码

$scope.choices = [{id: 1,purchaser_account:'',price:0,weight:0}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length+1;
   $scope.choices.push({'id':newItemNo,purchaser_account:'',price:0,weight:0});
};
以下是查看代码

<div  data-ng-repeat="choice in choices">
                        <div class="row">                           
                          <div class="col-md-3">
                            <div class="form-group label-floating">
                                <label class="control-label urdu-lable"> خریدار کھاتہ</label>
                                <select ng-model="choice.purchaser_account" name="account{{choice.id}}" class="form-control select2" required>
                                <option ng-repeat="x in purchaserAccount" value="{{x.id}}">{{x.name}}</option>
                                </select>
                            </div>
                         </div>
                            <div class="col-md-2">
                                <div class="form-group label-floating">
                                    <label class="control-label urdu-lable" > وزن</label>
                                    <input type="text" id="weight" ng-model="choice.weight"  class="form-control" required="required">
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group label-floating">
                                    <label class="control-label urdu-lable"> ریٹ</label>
                                    <input type="text" id="price" ng-model="choice.price"  class="form-control" required="required">
                                </div>
                            </div>

                            <div class="col-md-2">
                                <div class="form-group label-floating">
                                    <label class="control-label urdu-lable"> ٹوٹل</label>
                                    <div>{{((choice.price*(choice.weight/40))+((choice.price*(choice.weight/40))*.016)).toFixed(2)}}
                                    </div>
                                </div>
                            </div>


                            <div class="col-md-1">
                                <div class="form-group label-floating">
                                    <button class="remove" ng-show="$last" ng-click="removeChoice()">-</button>
                                </div>
                            </div>
                        </div>                    
                    </div>
<button class="btn btn-info" ng-click="addNewChoice()">Add fields</button>    

خریدار کھاتہ
{{x.name}
وزن
ریٹ
ٹوٹل
{((choice.price*(choice.weight/40))+((choice.price*(choice.weight/40))*.016)).toFixed(2)}
-
添加字段

你能帮我解决这个问题吗?

在你的角度添加函数上初始化选择

$scope.choices = [{id: 1,purchaser_account:'',price:0,weight:0}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length+1;
   $scope.choices.push({'id':newItemNo,purchaser_account:'',price:0,weight:0});
   $(".select2").select2();
};
在选择数组中添加第一个选项的位置初始化它