Javascript 角度模式形式-arrayIndex作为按钮onClick的参数
如何将arrayIndex作为参数传递给onClick中的函数?例如:Javascript 角度模式形式-arrayIndex作为按钮onClick的参数,javascript,angularjs,angular-schema-form,Javascript,Angularjs,Angular Schema Form,如何将arrayIndex作为参数传递给onClick中的函数?例如: { key:"someKey" type:"array", items:[ { "key":"someKey[].itemNo" }, { "type":"button", "onClick":"someFunction(someKey[arrayIndex].itemNo)" } ] } arrayIndex在“条件”下工作。但在函数中,
{
key:"someKey"
type:"array",
items:[
{
"key":"someKey[].itemNo"
},
{
"type":"button",
"onClick":"someFunction(someKey[arrayIndex].itemNo)"
}
]
}
arrayIndex在“条件”下工作。但在函数中,未定义是我得到的。我可以在someFunction中访问整个模型或表单的数据(即,我可以访问someKey),但我需要访问数组中的特定项(即,someKey[索引])
根据要求更新:
(摘自模式表单示例页)请参见“性能”按钮。我需要将按钮上下文中的电子邮件传递到函数中。
表格: 模式:
{
"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"
]
}
}
}
}
这是在添加了
arrayIndices
的同时添加的。请澄清问题。.在JSON中发布正确的项
数组。这样我才能帮助你someKey[].itemNo
这是什么意思。检查模式表单演示。这是放置数组元素的方法。我已经用schema forms Example更新了这个问题谢谢..你能分享你到目前为止尝试过的代码吗?现在我使用“事件”捕获点击事件,导航到父元素,从父元素中找到所需的值并使用它。这是一种丑陋的方式。除了实际的字段和值之外,我尝试使用的代码与上面列出的代码相同。
{
"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"
]
}
}
}
}