2015-09-28 99 views
0

我需要在我的ember-cli項目中使用它們。Ember-cli,砌體,同位素,包裝。如何使用?

如何開始?

我所著的終端:

bower install isotope --save

然後在我的燼-CLI-build.js我加app.import ecc...,但我不知道該怎麼辦。

哪裏把我的intialization腳本,像這樣:

$('.grid').isotope({ 
    // options 
    itemSelector: '.grid-item', 
    layoutMode: 'fitRows' 
}); 

如果我把它放在application.hbs它給我一個錯誤,當我改變與{{#link-to}}航線它不工作了。

怎麼辦?

在網絡上沒有太多關於此的資源。

回答

2

你應該創建一個組件:

ember g component isotope-grid

然後,在組件的didInsertElement勾應組件的jQuery的元素上調用isotope

import Ember from 'ember'; 

export default Ember.Component.extend({ 
    classNames: ['grid'], 

    didInsertElement() { 
     this.$().isotope({ 
     // options 
     itemSelector: '.grid-item', 
     layoutMode: 'fitRows' 
     }); 
    } 
}) 

然後,而不是使用<div class="grid"></div>,使用:

{{#isotope-grid}} 
    ... HTML goes here 
{{/isotope-grid}} 
+0

親愛的@丹尼爾,要關閉這個問題,我想知道如何在Ember中重現這個(http://codepen.io/desandro/pen/aGvIq),因爲按照你的回答,我有這個錯誤:'Uncaught TypeError:此$不是function'如果我使用此代碼:'didInsertElement(){ 此$()packery({ itemSelector: '.itemPack', 排水溝:20 \t \t \t})。。。; 。 \t \t \t此$()找到( 'itemPack')每個(函數(I,itemElem){ \t \t變種draggie =新Draggabilly(itemElem); \t \t //結合Draggabilly事件Packery 。 \t \t此$()packery( 'bindDraggabillyEvents',draggie); \t \t});' –

+0

這意味着什麼:'這$'在你的代碼()?爲什麼我必須使用它? –

+0

有些幫助嗎? –