我需要让我的单选按钮输出它们的json,如下所示:{回答:true}
当前架构:
"type" : "object",
"properties":{
"product":{
"name" : "Product XYZ Truck"
},
"question-154":{
"required": true,
"type":"string",
"enum": ["Q/RED", "Q/GREEN", "Q/BLUE", "Q/WHITE", "Q/BLACK"]
},
当前选项:
"fields": {
"question-154": {
"title":"Question-154",
"type": "radio",
"label": "Favorite Color",
"helper": "Pick your favorite color",
"optionLabels": {
"Q/RED": "Red",
"Q/GREEN": "Green",
"Q/BLUE": "Blue",
"Q/WHITE": "White",
"Q/BLACK": "Black"
}
},
"question-182": {
"title":"Question-182",
"type": "radio",
"label": "Engine",
"helper": "Pick your preferred engine",
"optionLabels": {
"Q1/h1": "Hybrid",
"Q1/e2": "Electric",
"Q1/d1": "Diesel",
"Q1/g1": "Gas"
}
}
现在它给了我
{“问题-154”:"Q/RED"}
但是,我实际上需要将其表示为:
{"Q/RED":"true"}
如何使用或修改Alpaca来以这种方式进行序列化?
发布于 2015-09-01 15:47:02
例如,您可以在提交按钮中修改结果:
"options": {
"form": {
"attributes": {
"action": "http://httpbin.org/post",
"method": "post"
},
"buttons": {
"submit": {
"click": function() {
方法this.getValue()是包含表单数据的javascript对象。您可以对其进行操作,例如将其发送到服务器。
您可以使用以下命令查看日志中的示例值:
console.log(JSON.stringify(this.getValue()));
https://stackoverflow.com/questions/30383889
复制相似问题