![](/img/trans.png)
[英]Ember list view (using #each helper and zynga scroller) with delayed content
[英]Getting the content rendered inside a #each ember template helper, without the #each content binding
/ START說明原因
我正在進行“加載更多”類型的交互:用戶進入頁面底部,我加載了更多內容。
當我使用一個以“ pinterest-style”(砌體)格式化內容的插件時,我需要獲取一個使用ember視圖格式化的rest調用的輸出,並且我正在做類似的事情:
<div id="list">
</div>
<div id="hidden" style="display:none">
{{#each item in App.itemsController}}
test {{item.id}}
<br />
{{/each}}
</div>
我想要做的是, load the content in the hidden div, and then pass its HTML generated content to the plugin to process in my formatted list view
。
如果我只復制#hidden內容,則進入Ember腳本,並在隨后的“更多加載”中, 除了進入#hidden div之外,還將內容插入#list中 。 那是因為我復制了整個車把。
因此,我擺脫了容器標記,本來是應該包裝控制器內容綁定的,但是即使將其從我傳遞給#list的內容中剝離出來,#list仍會在調用“加載更多內容”時自動更新。
我知道這是一件骯臟的事情,但是為了提高客戶端的性能,我必須采取類似的方法。
/ END說明原因
//實際問題;)
在這種背景下,問題是,要剝離容器變形腳本標記(如下面的標記),並只取其中的內容,是否應該擺脫自動更新內容的功能?
<script id="metamorph-X-start" type="text/x-placeholder"></script>
//ALL THE CONTENT
<script id="metamorph-X-end" type="text/x-placeholder"></script>
在這些里面,我只是生成了實際的內容,例如:
<script id="metamorph-9-start" type="text/x-placeholder"></script>
test <script id="metamorph-59-start" type="text/x-placeholder"></script>2873<script id="metamorph-59-end" type="text/x-placeholder"></script>
<br>
<script id="metamorph-9-end" type="text/x-placeholder"></script>
<script id="metamorph-10-start" type="text/x-placeholder"></script>
test <script id="metamorph-60-start" type="text/x-placeholder"></script>2872<script id="metamorph-60-end" type="text/x-placeholder"></script>
<br>
<script id="metamorph-10-end" type="text/x-placeholder"></script>
另一種選擇是通過編程的方式將模板呈現在變量中並進行處理,這無疑是一種更好的方法,但是我只是想知道#each綁定如何在內部工作,因為我認為變形是這樣做的。
您是否考慮過使用CollectionView
並通過didInsertElement
回調調用插件?
例如
MyList = Ember.CollectionView.extend({
itemViewClass: 'App.ListItem',
didInsertElement: function(){
view.$().jqueryPlugin({ ... })
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.