Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't want to use any tag(including the default div tag) in Ember.Collection View

Title may sound stupid, consider the following code

My Handlebars File

<table id="main-table">
  <tr>
    <td>
      <h1>Some Text</h1>
    </td>
    {{#collection myCollectionView}}
    <td>
      <table>
        <tr><td>{{view.someProperty}}</td></tr>
      </table>
    </td>    
    {{/collection}}
  </tr>
</table>

My View File

myCollectionView = Ember.CollectionView.extend({
  contentBinding: "myController.someArray",
  //someArray has say 4 elements
  itemViewClass: Ember.View.extend()
})

I want it to render the 4 tables inside the #main-table, it instead renders them outside the #main-table because it encloses my itemViewClass inside the default div tag. I can only change the tagName property but can't set it to nil I guess, any hack for this issue?

The JSFiddle

In response to the first answer The problem with {{each}} is that, I am using an EditableField as follows:
(just to sound clear, editable field is the one which changes a div to textfield on double click & back to div tag on focus out, simple widget built using ember)

updated Handlebars file

<table id="main-table">
  <tr>
    <td>
      <h1>Some Text</h1>
    </td>
    {{#collection myCollectionView}}
    <td>
      <table>
        <tr><td>{{view.myEditableField valueBinding="view.content"}}</td></tr>
      </table>
    </td>    
    {{/collection}}
  </tr>
</table>

updated view file

myCollectionView = Ember.CollectionView.extend({
  contentBinding: "myController.someArray",
  //someArray has say 4 elements
  itemViewClass: Ember.View.extend({
    alertFunc: function(){
      alert("content did change");
    }.observes('content')
  })
})

I want an observer to fire whenever the value in one of the editableField is changed, so that I can update my records in database. Can we accomplish this thing using {{each}} helper? also, arrayContentDidChange will only fire if the array length changes

like image 940
Mudassir Ali Avatar asked Dec 16 '22 20:12

Mudassir Ali


2 Answers

It is possible to do this in a Ember View

App.MyView = Ember.View.extend({
  tagName: ''
});
like image 115
Nath Avatar answered Apr 13 '23 17:04

Nath


AFAIK, there can't be Ember.View without "real presence" in the DOM, but you can use the {{each}} helper if you don't want to add a view that acts as a container (here a Ember.CollectionView).

Set tagName to null does not work, see Ember.View source code.

Template:

<script type="text/x-handlebars">
    <table id="main-table">
  <tr>
    <td>
      <h1>Some Text</h1>
    </td>
    {{#each App.content}}
      <td>
        <table><tr><td>{{name}}</td></tr></table>
      </td>
    {{/each}}
  </tr>
</table>
</script>​

Code:

App = Ember.Application.create();
App.content = [{name: "foo"}, {name: "bar"}, {name: "baz"}];

​ See this JSFiddle.

like image 40
louiscoquio Avatar answered Apr 13 '23 16:04

louiscoquio