在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ angular checkbox編輯怎么回顯返回的數(shù)據(jù)

angular checkbox編輯怎么回顯返回的數(shù)據(jù)

新增checkbox的數(shù)據(jù),編輯的時候怎么讓返回的數(shù)據(jù)處于選中效果,可以再次進行操作?

 <label class="needsclick" ng-repeat="color in group" style="margin-right: 10px;">
    <input type="checkbox" ng-checked="isChecked(color.tlid,color.type,color.name)" class="needsclick"
           ng-click="updateSelection($event,color.tlid,color.type,color.name)" />
    <span class="fa fa-check"></span>{{color.name}}
</label>
$scope.selected = [] ;
$scope.isChecked = function(id){
    console.log($scope.selected)
    return $scope.selected.indexOf(id) >= 0 ;
} ;
$scope.updateSelection = function($event,id,type,name){
    var checkbox = $event.target ;
    var checked = checkbox.checked ;
    if(checked){
        $scope.selected.push({      //提交的數(shù)據(jù)格式和返回的一樣是json 
            tlid:id,
            type:type,
            name:name
        }) ;
        $scope.formData.travelarrangeDetails=$scope.selected ;
        console.log( $scope.formData.travelarrangeDetails)
    }else{
        var idx = $scope.selected.indexOf(id) ;
        $scope.selected.splice(idx,1) ;
    }
} ;
//數(shù)據(jù)格式就是下面這種
$scope.selected={
 [
    name:"陳老板酒店"
    tlid:"7c2a2a4f-7cd3-44c8-a1e5-aac554d69ba4"
    type:1
],
 [
    name:"美食"
    tlid:"b40c8511-adf9-438e-90b4-5cd317ffd2f4"
    type:2
],
}
回答
編輯回答
毀與悔

clipboard.png

不用的參數(shù) 最好不要寫上去,代碼簡潔一點。

isChecked這個方法改一下。

$scope.isChecked = function(id){
    console.log($scope.selected)
    return $scope.selected.tlid == id;
} ;

$scope.selected是一個數(shù)組 修改一下方法

$scope.isChecked = function(id){
    var is = false; //新建一個標(biāo)識
    $scope.selected.forEach(function(item){
      if(item.tlid == id){
        is = true;
      }
    })
    return is;
} ;
2017年3月1日 09:52