angularjs中有多个Checkboxes错误

时间:2016-09-16 06:08:58

标签: javascript angularjs

我的程序中有多个复选框,但它不起作用。我在下面给出我的代码。请检查并让我知道我在哪里做错了。我是angularjs的初学者。

HTML代码:

db.open();

        //for insert in db
        ContentValues cv = new ContentValues();
        cv.put("ProjectNo", "ProjectNo");
        cv.put("ProjectId", "ProjectId");
        cv.put("SealingNumber", "SealingNumber");
        cv.put("ConsAcNo", "ConsAcNo");
        cv.put("KnoNo", "KnoNo");
        cv.put("MeterSrMo", "MeterSrMo");
        cv.put("ThirdParty", "ThirdParty");
        cv.put("BookNumber", "BookNumber");
        cv.put("SupplyType", "SupplyType");
        cv.put("ConsName", "ConsName");
        cv.put("ConsAddress1", "ConsAddress1");
        cv.put("ConsAddress2", "ConsAddress2");
        cv.put("ConsAddress3", "ConsAddress3");
        cv.put("TelephoneNo", "TelephoneNo");
        cv.put("ConsMobileNo", "ConsMobileNo");
        cv.put("SanctionLoad", "SanctionLoad");
        cv.put("MeterMake", "MeterMake");
        cv.put("MeterType", "MeterType");
        cv.put("PhaseType", "PhaseType");
        cv.put("IsCompleted", "IsCompleted");
        cv.put("Contractor", "Contractor");

        //your where condition (change as per your requirement)
        String whereClause = "ProjectNo = " + "PROJECT_NUMBER" + " AND " + "ProjectId" + " = PROJECT_ID" + "AND "
            + "SealingNumber =" + "SealingNumber" + "AND" + " ConsAcNo = " + "ConsAcNo" + "AND" + "KnoNo = " + "KnoNo"
            + "AND" + "MeterSrMo = " + "MeterSrMo";

        Log.e("where ", "-->>" + whereClause);
        //to get count if it is more than zero than update else insert to table
        String query = "SELECT count( * ) as count from myTable where " + whereClause;

        //check count if that value exists in db
        if (query.trim().length() <= 0) {
            db.insert(myTable, intCode, cv); //intCode is primary key
        } else {
            db.update(myTable, cv, whereClause, null);
        }
        db.close();

控制器代码:

<div class="row">
    <ul>
        <li class="col s6 m2" data-ng-repeat="item in amenities.general_amenities track by item.id">
            <input type="checkbox"ng-model="checkboxModel.value" checked>
            <label for="general_amenities">
                <span data-ng-bind="item.amenities"></span>
            </label>
        </li>
    </ul>
</div>

继续相同的问题我正在添加一个快照和代码,我想在点击添加按钮时创建具有相同文本的类似行。

enter image description here

HTML:

.controller(
    'appCtrl',
    ["$scope", '$connectivityModel',
    function ($scope, $cm) {
        angular.extend($scope, {
            common: [],
            $scope : checkboxModel = {
                value : true,
            },

1 个答案:

答案 0 :(得分:0)

var app = angular.module('myApp', []);
		  app.controller('appCtrl', function($scope){
		    $scope.checkboxs = [
	        { name: "Red", id: 0, isChecked: true }, 
	        { name: "Blue", id: 1, isChecked: false }, 
	        { name: "Green", id: 2, isChecked: true },
	        { name: "Yellow", id: 3, isChecked: true }, 
	        { name: "Orange", id: 4, isChecked: false }, 
	        { name: "Purple", id: 5, isChecked: true }
    		];
		  });
<!doctype html>
<html>
  <head>
    <title>My Angular App</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  </head>
  <body>
  	<div ng-app="myApp" ng-controller="appCtrl">
		  <label ng-repeat="check in checkboxs">
		      <input type="checkbox" ng-model="check.isChecked" /> {{check.name}} 
		  </label>
  </body>

var app = angular.module('myApp', []);
		  app.controller('appCtrl', function($scope){
		     $scope.checkboxs = {checkbox1: true, checkbox2: false};
		  });
<!doctype html>
<html>
  <head>
    <title>My Angular App</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  </head>
  <body>
  	<div ng-app="myApp" ng-controller="appCtrl">
		  <label ng-repeat="(check,enabled) in checkboxs">
		      <input type="checkbox" ng-model="checkboxs[check]" /> {{check}} 
		  </label>
  </body>

</html>

希望它适合你。