2012-08-30 32 views
4

標題可能聽起來很蠢,考慮下面的代碼不想使用任何標籤(包括默認div標籤)在Ember.Collection查看

我的手把文件

<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> 

我查看文件

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

我希望它渲染#主表中的4個表,它,而不是使他們的#main-外因爲它將我的itemViewClass包含在默認的div標記中。我只能更改tagName屬性,但不能將其設置爲零我想,這個問題的任何破解?

The JSFiddle

在響應於第一答案 與{{每個}}是,我使用如下的EditableField問題:
(只是要清晰,可編輯的字段是其中一個改變一個div上雙擊文本框&回焦點了div標籤,簡單的小工具使用燼)內置

更新把手文件

<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> 

更新視圖文件

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

我想只要在editableField的一個值變爲觀察員開火,這樣我就可以在數據庫中更新我的記錄。我們可以使用{{each}}幫手完成這件事嗎?另外,arrayContentDidChange只會在數組長度發生變化時觸發

+0

?也許你可以用一個簡單的'

+0

來代替它。你仍然可以訪問子視圖/父視圖,就像這個JSFiddle一樣:http://jsfiddle.net/ZsrWe /。如果它仍然不夠,也許你將不得不使用'Ember.ContainerView'。但個人而言,我認爲您的模板並非真正乾淨,例如,「CollectionView」應該更多地用作''或直接用作'

'。 – louiscoquio

+0

@ sly7_7:[jsFiddle for Editable Field](http://jsfiddle.net/ZsrWe/3/) –

回答

4

AFAIK,在DOM中沒有「真實存在」的情況下不能有Ember.View,但是如果您不想添加一個幫助器,則可以使用{{each}}幫助器視圖充當一個容器(這裏是一個Ember.CollectionView)。

設置tagNamenull不起作用see Ember.View source code

模板:

<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>​ 

代碼:

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

this JSFiddle

+1

Fine louis,+1。感謝您的時間幫助人們:) –

+0

@louiscoquio:感謝您的回覆,但請參閱最新的問題,對不起,我沒有在 –

8

這是可能的,你可以發佈myEditableFieldView的代碼來做到這一點的灰燼查看

App.MyView = Ember.View.extend({ 
    tagName: '' 
}); 
+1

之前添加這個細節也是錯誤的作品。但不是空的。我認爲這是因爲這個問題最初是被問到的。 –

+2

'tagName:'''在更改路線時會導致錯誤。我的觀點在路線改變時不會被破壞。 (ember 1.2) – guleria

+1

在燼1.9.1 - tagName:''的作品,但將其設置爲false不。 – Nathan