json-forms icon indicating copy to clipboard operation
json-forms copied to clipboard

SchemaResolver with array of objects of dynamic

Open abelchun39 opened this issue 8 years ago • 2 comments

I had an array of objects A and each of object contains filter. Each filter options will display different kinds of forms objects dynamically.

Based on the issue https://github.com/brutusin/json-forms/issues/22, the dynamic done in the first layer of the object. But I have array of objects A that doesn't work for each display.

var schema = {
  "properties": {
    "ObjectA": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": { "filter": ...., "criteria": { "dependOn": ['filter'] } }
      }
    }
  }
}
var dynamicSchema = {
  "age": { type: "Object",  number: 21 },
  "country": { type: "Object", name: "US" }
}


var BrutusinForms = brutusin["json-forms"];
this.bf = BrutusinForms.create(schema);
this.bf.schemaResolver = (names, data, cb) => {
  data.ObjectA.map((obj, ind) => {
  schemas["$.ObjectA[" + ind + "].criteria"] = dynamicSchema[obj.filter]
  }
  cb(schemas);
}
this.bf.render(this.$refs.manageContainer);

The name always outputs schemas["$.demographic[#].criteria"] no matter which filter I add. If I add schemas["$.demographic"], it works for me without the filter but the dynamic schema objects.

abelchun39 avatar Nov 28 '17 08:11 abelchun39

https://github.com/brutusin/json-forms/blob/master/README.md#status

idelvall avatar Dec 14 '17 11:12 idelvall

hello, did you solve this problem? I also meet this problem, thanks!

OYE93 avatar Nov 02 '18 04:11 OYE93