Pregunta

I searched and found this question (GUI-based or Web-based JSON editor that works like property explorer) that has several links to resources that generate UI from JSON.

I am interested in any examples or known projects that show emberjs working with JSON Schema (http://json-schema.org/) to generate on-the-fly Forms. Projects such as:

Any Ideas?

¿Fue útil?

Solución

Yes you can trivially generate forms dynamically based on some JSON.

You will need to map your JSON object into an array of keys in your router (or controller):

model: function() {
  var json = {a: 'red', b: 'yellow', c: 'blue'};
  var items = [], key;
  for (key in json) {
    if (json.hasOwnProperty(key)) {
      items.push({name: key, value: json[key]});
    }
  }
  return items;
}

And just use the each helper in your view:

{{#each field in content}}
  {{field.name}}: {{input type="text" value=field.value}}<br>
{{/each}}

I made a working JSBin with the above code.

Otros consejos

There is Ember addon - ember-cli-dynamic-forms.

This addon is powered by alpacajs.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top