Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ryan is right about the attributes, but it takes some doing to actually get where you're going. My examples here are using the latest RC1 Ember.</p> <p>Here is an editor template that is model agnostic:</p> <pre><code>&lt;script type="text/x-handlebars" data-template-name="edit_monster"&gt; {{#if clientId}} &lt;h1&gt;Edit Monster: {{name}}&lt;/h1&gt; &lt;div&gt; {{#each metadata}} &lt;span class="edit-label"&gt;{{name}}&lt;/span&gt; &lt;span class="edit-field"&gt; {{view App.AutoTextField typeBinding="type" nameBinding="name" }} &lt;/span&gt; {{/each}} &lt;/div&gt; {{else}} No monster selected. {{/if}} &lt;/script&gt; </code></pre> <p>To make that work, we need a couple of pieces of magic-magic. This controller is a good start:</p> <pre><code>App.EditMonsterController = Em.ObjectController.extend({ metadata: function() { var vals = []; var attributeMap = this.get('content.constructor.attributes'); attributeMap.forEach(function(name, value) { vals.push(value); }); return vals; }.property('content') }); </code></pre> <p>That uses that "attributes" property that Ryan mentioned to provide the metadata that we are feeding into our #each up there in the template!</p> <p>Now, here is a view that we can use to provide the text input. There's an outer container view that is needed to feed the valueBinding in to the actual textfield.</p> <pre><code>App.AutoTextField = Ember.ContainerView.extend({ type: null, name: null, init: function() { this._super(); this.createChildView(); }, createChildView: function() { this.set('currentView', Ember.TextField.create({ valueBinding: 'controller.' + this.get('name'), type: this.get('type') })); }.observes('name', 'type') }); </code></pre> <p>Here is a fiddle demonstrating the whole crazy thing: <a href="http://jsfiddle.net/Malkyne/m4bu6/" rel="nofollow">http://jsfiddle.net/Malkyne/m4bu6/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload