簡體   English   中英

在羊駝 object 上添加數組類型和 select 類型

[英]Adding array type and select type on alpaca object

我有這個羊駝頁面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);
});

在其中我想要一個數組類型和一個遠程獲取數據的 select 框。 遠程數據是這種格式

{
    "data": {
        "Vanilla": "Vanilla Flavor",
        "Chocolate": "Chocolate Flavor",
        "Strawberry": "Strawberry Flavor",
        "Mint": "Mint Flavor"
    }
}

我得到錯誤

{“消息”:“無法找到類型為 class 的字段:未定義”,“原因”:“FIELD_INSTANTIATION_ERROR”}

我怎樣才能解決這個問題?

我這樣解決了

$(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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM