簡體   English   中英

使用Angular.js在下拉列表中使用多項功能時出錯

[英]Getting error while using mulitple in drop down list using Angular.js

我有一個大問題。我需要從下拉列表中選擇多個值,為此我使用bootstrap-multiselect.js遇到以下錯誤。

angularjs.js:107 TypeError: a.forEach is not a function
    at u.writeValue (angularjs.js:273)
    at f.$render (angularjs.js:285)
    at Object.<anonymous> (angularjs.js:265)
    at n.$digest (angularjs.js:130)
    at n.$apply (angularjs.js:133)
    at HTMLInputElement.<anonymous> (angularjs.js:253)
    at HTMLInputElement.m.event.dispatch (jquery.js:4670)
    at HTMLInputElement.r.handle (jquery.js:4338)

這里我有下面的按鈕。當用戶單擊此按鈕時,下拉列表將動態加載。

<input type='button' class='btn btn-xs btn-green' value='Send' ng-click="sendVoucherCode(code.voucher_code_id,code.expired_date,code.customer_name);" ng-hide="sendButton">  

當用戶單擊上方按鈕時,以下下拉列表必須動態加載。

<select class="form-control"  id="lstFruits" ng-model="voucher_code" ng-options="code.name for code in listOfCode track by code.value " ng-change="removeBorder('lstFruits')"  multiple="multiple">
 </select>

上面的下拉列表的控制器端代碼如下。

    $scope.sendVoucherCode=function(voucherid,expierdate,cname){
        $scope.listOfCode=[{
        name:'Select Voucher Code',
        value:''
    }]
    $scope.voucher_code=$scope.listOfCode[0];
        var code={'voucher_code_id':voucherid};
            $http({
                method:'POST',
                url:"php/getVoucherNotifyCode.php",
                data:code,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            }).then(function successCallback(response){
                console.log('voucher code',response.data);
                $scope.codeImage=response.data[0].image;
                $scope.arrCode=response.data[0].generated_code.split(',');
                for(var i=0;i<$scope.arrCode.length;i++){
                    var data={'name':$scope.arrCode[i],'value':$scope.arrCode[i]};
                    $scope.listOfCode.push(data);
                }
            },function errorCallback(response) {
            })
    }
$('#lstFruits').multiselect({
           includeSelectAllOption: true
      });

在這里,當上面的函數被調用時,錯誤將出現並且下拉框沒有打開。這里我還需要當用戶單擊發送按鈕時,動態值將加載到下拉列表中,並且用戶可以獲取一個/多個值,這些值將再次在控制器端函數內部收集。請幫助我解決此問題。

好像voucher_code沒有與數組綁定。 如果將multiselect與對象綁定,則會出現此錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM