gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 22:58:20 26 4
gpt4 key购买 nike

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

{
key:"someKey"
type:"array",
items:[
{
"key":"someKey[].itemNo"
},
{
"type":"button",
"onClick":"someFunction(someKey[arrayIndex].itemNo)"
}
]
}

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

按要求更新:(取自模式表单示例页面)

请参阅执行操作按钮。我需要将按钮上下文中的电子邮件传递到函数中。

形式:

[

{
"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"
]
}
}
}
}

最佳答案

这是在 v1.0.0-alpha.1 中添加的添加arrayIndi​​ces

关于javascript - Angular Schema Form - arrayIndex 作为按钮 onClick 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37378650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com