如何创建复选框的 angular 模式表单清单?

How to create angular schema form checklist of checkboxes?

不太确定如何呈现此列表。我正在尝试创建一种从自定义对象创建的复选框形式。

这是我第一次使用 angular-schema-form 但我在这里运气不好。

这是我的 plunker.

var app = angular.module('plunker', ['ngSanitize', 'schemaForm']);

app.controller('MainCtrl', function($scope) {
  $scope.schema = {
    "type": "object",
    "title": "Comment",
    "properties": {
      "comment": {
        "type": "checkboxes"
      }
    },
    "required": [
      "comment"
    ]
  };

  $scope.form = [
    {
      key: "comment",
      type: "checklist",
      titleMap: [{value: "1", name: "First"}]
    }
  ];

  $scope.model = {
    "name": "Jon Snow"
  };
});

没有checkboxes字段类型。但是有两个选项可以定义几个复选框:

  1. boolean 字段类型的用法
  2. 通过指定 items 数组来使用 array 字段类型。

我更新了你的代码:

$scope.schema = {
  "type": "object",
  "title": "Comment",
  "properties": {
    "comment": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "first": {
            "type": "boolean",
            "title": "First Checkbox"
          },
          "second": {
            "type": "boolean",
            "title": "Second Checkbox"
          },
          "third": {
            "type":"boolean",
            "title": "Third Checkbox"
          }
        }
      }
    },
    "comment2": {
      "type": "boolean",
      "title": "Standalone Checkbox"
    }
  }
};

$scope.form = [
  "*",
  {
    type: "submit",
    title: "Save"
  }
];

$scope.model = {};

要让某些复选框默认选中,您可以使用相应的 属性 名称,如下所示:

$scope.model = {
  comment2: true,
  comment: [{
    second: true
  }]
};

更多详情请查看plunker