2014-01-30 23 views
5

我有一些複選框,它們的值在數據庫中是'Y'或'N'作爲enum.for更新我必須檢查所有複選框,以查看複選框爲選中狀態。 這是複選框將複選框設置爲使用angularjs檢查

<label class="radio-inline"> 
    <input type="checkbox" ng-model="newItem.have_voter_id" value="have_voter_id" /><?php echo $this->lang->line('label_voter_id'); ?> 
</label> 
<label class="radio-inline"> 
    <input type="checkbox" ng-model="newItem.have_passport" value="passport" /> <?php echo $this->lang->line('label_passport'); ?> 
</label> 

代碼,這是視圖和更新用

$scope.edit = function(id,family_id) { 

    $scope.action = 'update'; 
    FamilyMem.get({id:id,family_id:family_id}, function (response) { // success    
     $scope.newItem = response.data; // store result to variable    
      $("#myModal").modal('show'); 
     }, function (error) { // ajax loading error 
      Data.errorMsg(); // display error notification 
      //$scope.edit = false; 
     }); 
    }; 

和編輯按鈕

<a href="" class="btn btn-magenta btn-sm" ng-click="edit(family_member.id,family_member.family_id)"> 

回答

14

使用ng-checked爲的複選框,

<label class="radio-inline"> 
    <input type="checkbox" ng-model="newItem.have_voter_id" value="have_voter_id" ng-checked="newItem.have_voter_id=='Y'"/><?php echo $this->lang->line('label_voter_id'); ?> 
</label> 

<label class="radio-inline"> 
    <input type="checkbox" ng-model="newItem.have_passport" value="passport" ng-checked="newItem.have_passport=='Y'"/> <?php echo $this->lang->line('label_passport'); ?> 
</label> 
0

模型newItem.have_voter_idnewItem.have_passport的功能被設置爲truefalse根據你對複選框的操作。如果選中'voter_id'複選框,則模型newItem.have_voter_id的值將更新爲true,如果未選中,則值將更新爲false。其他複選框也是如此。

+0

用於保存從複選框值我做that.but而我想更新它再次爲未選中顯示即使它是在數據庫 –

+0

真正你能請一把小提琴?用這些較少的代碼很難找出問題。 –

相關問題