简体   繁体   English

Ember.js,如何在视图中使用Javascript?

[英]Ember.js, How do I use Javascript in a view?

I'm pretty new to Ember and I'm having a problem that googling and reading the docs hasn't helped me with much yet. 我对Ember还是很陌生,但是我遇到了一个问题:谷歌搜索和阅读文档并没有太大帮助。 In my index view, I have a small <ul> that I'm using roundabout.js on to make it into a carousel slider. 在索引视图中,我有一个小的<ul> ,我正在使用roundabout.js使其成为轮播滑块。 The problem, is that for the life of me, I can't get Ember to let me use Javascript on the DOM. 问题是,为了我一生,我无法让Ember让我在DOM上使用Javascript。 :( Any advice would be very appreciated. :(任何建议将不胜感激。

The <ul> looks like: <ul>看起来像:

<ul id="games">
                <li class="god"><img src="{{URL::asset('images/doge.png')}}" alt="doge" height="400" width="400"/></li>
                <li class="doge">Wow</li>
                <li class="doge">Much move</li>
                <li class="doge">Many Smooth</li>
                <li class="doge">Doge is world</li>
                <li class="doge">Very slide</li>
                <li class="doge">Amaze</li>
                <li class="doge">To the moon!</li>
</ul>

And the code to make it into a carousel is: 使它成为轮播的代码是:

    $('#games').roundabout({
    minZ: 100,
    maxZ: 300,
    tilt: -4,
    childSelector: '.doge'
    });

And the finished product should look like: 成品看起来应该像这样: 在此处输入图片说明

Here's the ember code I used following @fanta's advice: 这是我遵循@fanta的建议使用的炭烬代码:

App.Index= Ember.View.extend({      
    didInsertElement : function(){
         Ember.run.schedule('afterRender', function(){
            $('#games').roundabout({
            minZ: 100,
            maxZ: 300,
            tilt: -4,
            childSelector: '.doge'
            });
         });
    }
});

ok, here is JSFiddle with what I've told you, the only thing is that I copied and pasted the carousel code there, just go to the relevant code 好的,这是JSFiddle,其中包含我所告诉的内容,唯一的是我在此处复制并粘贴了轮播代码,只需转到相关代码即可

http://jsfiddle.net/NQKvy/792/ http://jsfiddle.net/NQKvy/792/

App.IndexView = Ember.View.extend({
  didInsertElement: function() {
    Ember.run.schedule('afterRender', function() {
        $('#games').roundabout({
            minZ: 100,
            maxZ: 300,
            tilt: -4,
            childSelector: '.doge'
        });
    });
  }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM