2017-01-27 1 views
0
아래

는 HTML체크리스트 모델 및 체크리스트 값이 모델을 업데이트하지 않거나

<label ng-repeat="(index, item) in field.optionValue"> 
      <input type="checkbox" 
      checklist-model="formControlsValues[dbColumnName]" 
      checklist-value="item">{{field.optionName[index]}} 
     </label> 

field.optionValuefield.optionName의 내용입니다 예상대로 작동하지 않는 것은 배열

에게 있습니다

필드 = {optionValue를 : "1", "2", "3",이 Optionname : "XXX", "YYY", "ZZZ"]}

checklist-model, formControlsValues ​​[dbColumnName]은 체크 박스가 선택/체크되었을 때 값을 채울 것으로 예상되는 동적 객체 모델입니다. formControlsValues는 [dbColumnName] $ scope.formControlsValues.Village 또는 컨트롤러 $ scope.formControlsValues.State 것이다 렌더링 후술된다 채우는 예상 포맷 $ scope.formControlsValues.Village =
[ "2", "1"]

+0

사람이 주변에서 작업 좀 도와 주시겠습니까? – teenu

답변

1

나는 해냈다. 작동하고 있습니다.

http://jsfiddle.net/fxsu6e79/1/

$scope.formControlsValues={ 
    State:[ 
    "1","3" 
    ], 
    Village:[ 
    "2","3" 
    ] 
}; 

은 괜찮습니다?

+0

안녕하세요. @ 핑거 피치. 우선이 일을 해줘서 고맙다. [ "1", "2", "3", 이 Optionname : [ "XXX", "YYY", "ZZZ"] dbColumnName : 개체 $ scope.field = { optionValue를이어야 " 상태 " } 여기서 $ Values.field.State 값을 추적 할 수 있습니다. – teenu

+0

또한"checklist-model "을 인젝터라고 추가해야합니까? – teenu

+0

나는 그것을 고쳤다. http://jsfiddle.net/fxsu6e79/3/ – fingerpich

1
<div ng-controller="DemoCtrl"> 
    <label ng-repeat="(index,value) in field.optionValue"> 
    <input type="checkbox" checklist-model="formControlsValues[field.dbColumnName]" checklist-value="value"> {{field.optionName[index]}} 
    </label> 
    values : {{ formControlsValues[dbColumnName]}} 
</div> 

스크립트

angular.module("DemoApp", ["checklist-model"]) 
.controller('DemoCtrl', function($scope) { 
    $scope.field = { 
     optionValue : ["1","2","3"], 
     optionName : ["xxx", "yyy", "zzz"], 
     dbColumnName : "State" 

    } 
    $scope.dbColumnName="State"; 
    $scope.formControlsValues={ 
     State:[] 
    }; 
}); 

예를 참조하십시오 : 여기 http://jsfiddle.net/KarthikParameswaran/fxsu6e79/4/

1

가 작동 코드입니다. 나중에 문제가 발생할 수 있으므로 문자열 대신에 숫자를 큰 따옴표로 묶어야한다는 점을 지적하고자합니다.

// Code goes here 
 

 
var app = angular.module('checkList', ["checklist-model"]); 
 

 
app.controller('checkListCtrl', function ($scope) { 
 
    $scope.formControlsValues = {}; 
 
    $scope.field = { 
 
     optionValue : ["1","2","3"], 
 
     optionName : ["xxx", "yyy", "zzz"], 
 
     dbColumnName : "State" 
 
    }; 
 
    
 
    $scope.dbColumns = ['State', 'Village']; 
 
    $scope.formControlsValues = { 
 
    Village : [], 
 
    State : [] 
 
    } 
 
});
<!DOCTYPE html> 
 
<html ng-app="checkList"> 
 

 
    <head> 
 
    <script data-require="[email protected]" data-semver="1.6.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.js"></script> 
 
    <script data-require="[email protected]*" data-semver="0.0.1" src="http://vitalets.github.io/checklist-model/checklist-model.js"></script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script src="script.js"></script> 
 
    </head> 
 

 
    <body ng-controller="checkListCtrl"> 
 
     <h4>Checklist model</h4> 
 
     <div> 
 
     <label ng-repeat="(index, item) in field.optionValue"> 
 
      <input type="checkbox" 
 
      checklist-model="formControlsValues[field.dbColumnName]" 
 
      checklist-value="item">{{field.optionName[index]}} 
 
     </label> 
 
     </div> 
 
     <br /> 
 
     <div> 
 
     <select ng-model="field.dbColumnName" ng-options="d for d in dbColumns"></select> 
 
     </div> 
 
     <div> 
 
      <label>Selected Villages: {{formControlsValues.Village}}</label> 
 
     </div> 
 
     <div> 
 
     <label>Selected States: {{formControlsValues.State}}</label> 
 
     </div> 
 
    </body> 
 

 
</html>