[英]Adding array type and select type on alpaca object
I have this alpaca page https://jsfiddle.net/knh9yrje/ with the following schema我有这个羊驼页面https://jsfiddle.net/knh9yrje/具有以下架构
$(document).ready(function() {
let form = {
"view": "bootstrap-edit",
"data": {
name: "John Matrix",
age: 40,
ice: ["Vanilla", "Chocolate"],
items: [{
"flavor": "strawberry",
"topping": "nuts"
}, {
"flavor": "chocolate",
"topping": "raisin"
}]
},
"schema": {
"type": "object",
"properties": {
"items": {
"title": "Ice Cream",
"type": "array",
"properties": {
"flavor": {
"title": "Flavor",
"description": "Ice cream flavor",
"type": "string"
},
"topping": {
"title": "Topping",
"description": "Ice cream topping",
"type": "string"
}
}
},
"ice": {
"title": "Ice cream",
"helper": "Guess my favorite ice cream?",
"type": "select",
"multiple": true,
"dataSource": "http://localhost:8000/data_routes/icecream_list"
},
"name": {
"title": "Full Name",
"type": "string"
},
"age": {
"title": "Age",
"type": "number"
},
"description_required": {
"enum": [
"Y",
"N"
],
"required": true
},
"description": {
"required": true
}
},
"dependencies": {
"description": ["description_required"]
}
},
"options": {
"fields": {
"description_required": {
"type": "select",
"noneLabel": "Select an Option",
"label": "Description Required"
},
"description": {
"type": "textarea",
"cols": 5,
"label": "Description",
"dependencies": {
"description_required": "Y"
}
}
}
}
}
$("#form").alpaca(form);
});
In it i want to have an array type and a select box that fetches data remotely.在其中我想要一个数组类型和一个远程获取数据的 select 框。 The remote data is of this format
远程数据是这种格式
{
"data": {
"Vanilla": "Vanilla Flavor",
"Chocolate": "Chocolate Flavor",
"Strawberry": "Strawberry Flavor",
"Mint": "Mint Flavor"
}
}
I get error我得到错误
{"message":"Unable to find field class for type: undefined","reason":"FIELD_INSTANTIATION_ERROR"}
{“消息”:“无法找到类型为 class 的字段:未定义”,“原因”:“FIELD_INSTANTIATION_ERROR”}
How can i fix this?我怎样才能解决这个问题?
I solved it like this我这样解决了
$(document).ready(function() {
let form = {
"view": "bootstrap-edit",
"data": {
name: "John Matrix",
age: 40,
ice: ["Vanilla", "Chocolate"],
items: [{
"flavor": "strawberry",
"topping": "nuts"
}, {
"flavor": "chocolate",
"topping": "raisin"
}]
},
"schema": {
"type": "object",
"properties": {
"items": {
"title": "Ice Cream",
"type": "array",
"properties": {
"flavor": {
"title": "Flavor",
"description": "Ice cream flavor",
"type": "string"
},
"topping": {
"title": "Topping",
"description": "Ice cream topping",
"type": "string"
}
}
},
"name": {
"title": "Full Name",
"type": "string"
},
"age": {
"title": "Age",
"type": "number"
},
"ice": {
"title": "Ice",
"type": "select"
},
"description_required": {
"enum": [
"Y",
"N"
],
"required": true
},
"description": {
"required": true
}
},
"dependencies": {
"description": ["description_required"]
}
},
"options": {
"fields": {
"ice": {
"title": "Ice cream",
"helper": "Guess my favorite ice cream?",
"type": "select",
"multiple": false,
"dataSource": "http://localhost:8000/data_routes/icecreal_list"
},
"description_required": {
"type": "select",
"noneLabel": "Select an Option",
"label": "Description Required"
},
"description": {
"type": "textarea",
"cols": 5,
"label": "Description",
"dependencies": {
"description_required": "Y"
}
}
}
}
}
$("#form").alpaca(form);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.