문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

This addon is powered by alpacajs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top