Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度模式形式数组长度_Javascript_Angularjs_Angular Schema Form - Fatal编程技术网

Javascript 角度模式形式数组长度

Javascript 角度模式形式数组长度,javascript,angularjs,angular-schema-form,Javascript,Angularjs,Angular Schema Form,我有这个模式: { "type": "object", "title": "Comment", "required": [ "comments" ], "properties": { "comments": { "type": "array", "items": { "type": "object", "properties": { "name":

我有这个模式:

    {
     "type": "object",
     "title": "Comment",
     "required": [
     "comments"
      ],
  "properties": {
    "comments": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "title": "Name",
            "type": "string"
          },
          "email": {
            "title": "Email",
            "type": "string",
            "pattern": "^\\S+@\\S+$",
            "description": "Email will be used for evil."
          },
          "spam": {
            "title": "Spam",
            "type": "boolean",
            "default": true
          },
          "comment": {
            "title": "Comment",
            "type": "string",
            "maxLength": 20,
            "validationMessage": "Don't be greedy!"
          }
        },
        "required": [
          "name",
          "comment"
        ]
      }
    }
  }
}
这是一组注释。我可以添加和删除评论

默认情况下,如何始终呈现阵列的2项


我试过使用
maxtems
minItems
,但这些参数不呈现项目。

目前有两种方法

首先是在默认模型中设置它们,使其看起来像:

$scope.model = {
    "comments": [{},{}]
}
第二种方法是在阵列上使用onChange:

"onChange": function(val) { if(val.length < 2) val.push({}); }
“onChange”:函数(val){if(val.length<2)val.push({});}
两者之间的区别在于onChange将不允许其下降到您设置的最小长度以下,而第一个选项仅用于初始默认值