Angular Schema Form - arrayIndex作为按钮onClick的参数

时间:2016-05-22 19:23:43

标签: javascript angularjs angular-schema-form

如何将arrayIndex作为参数传递给onClick中的函数?例如:

{
  key:"someKey"
  type:"array",
  items:[
    {
      "key":"someKey[].itemNo"
    },
    {
      "type":"button",
      "onClick":"someFunction(someKey[arrayIndex].itemNo)"
    }
  ]
}
“条件”中的

arrayIndex有效。但是在函数中,undefined是我得到的。我能够在someFunction中访问整个模型或表单的数据(即我可以访问someKey),但我需要访问数组中的特定项(即someKey [index])。

按要求更新 (取自架构表格示例页面)

请参阅performAction按钮。我需要将按钮上下文中的电子邮件传递给函数。

形式:

[

  {
    "key": "comments",
    "add": "New",
    "style": {
      "add": "btn-success"
    },
    "items": [
      "comments[].name",
      "comments[].email",
      {
        "key": "comments[].spam",
        "type": "checkbox",
        "title": "Yes I want spam.",
        "condition": "model.comments[arrayIndex].email"
      },
      {
        "key": "comments[].comment",
        "type": "textarea"
      },
      {
        "type":"button",
        "onClick":"performAction(comments[arrayIndex].email)",
        "title":"Perform Action"
      }
    ]
  },
  {
    "type": "submit",
    "style": "btn-info",
    "title": "OK"
  }
]

架构:

{
  "type": "object",
  "title": "Comment",
  "required": [
    "comments"
  ],
  "properties": {
    "comments": {
      "type": "array",
      "maxItems": 2,
      "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"
        ]
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

v1.0.0-alpha.1添加了arrayIndices