Backbone和Smart Time之前没有一起运作,任何想法?

时间:2012-12-04 04:06:23

标签: jquery ruby-on-rails backbone.js coffeescript

我正在使用骨干和: https://github.com/pragmaticly/smart-time-ago

当我加载页面时,没有显示前一段时间应该是什么(但主干正在工作)。

这是我的主干观点:

class Voice.Views.PostsIndex extends Backbone.View

        template: JST['posts/index']

        initialize: ->
                @collection.on('reset', @render, this)

        render: ->
                $(@el).html(@template(posts: @collection)).timeago
                this

模板/帖/ index.jst.eco

<% for post in @posts.models: %>
        <tbody id="postdata"><tr><td>
                <center>
                <% if post.get('content').length > 140: %>
                        <%=post.get('content').substring(0, 140)+"\t\t"%>
                        ...<a href="show/<%= post.get('id') %>">see more</a>
                <% else: %>
                        <%= post.get('content') %>
                <% end %>
        <br>    </center>
        <span class="green pull-left"><%= post.get('agrees') %>&nbsp;</span>
        <span class="red pull-left"><%= post.get('disagrees') %>&nbsp;</span>
        <span class="blue pull-left">0</span>
        <span class="pull-right">
            <time class="timeago" datetime="<%=post.get('created_at')%>">
            </time>
        </span>
        </td></tr></tbody>

的application.js

//= require jquery
//= require jquery_ujs
//= require timeago
//= require underscore
//= require backbone
//= require voice
//= require bootstrap.min
//= require_tree ../templates
//= require_tree ./models
//= require_tree ./collections
//= require_tree ./views
//= require_tree ./routers
//= require_tree .

有没有让这个工作?提前致谢

1 个答案:

答案 0 :(得分:1)

这不是函数调用:

$(@el).html(@template(posts: @collection)).timeago

这只是在jQuery对象上查找timeago函数,并且对它没有任何作用。您需要添加括号(或参数)来调用timeago

$(@el).html(@template(posts: @collection)).timeago()
# you need these ---------------------------------^^

如果您提供一些参数,则不需要括号:

$(@el).html(@template(posts: @collection)).timeago selector: '.pancakes'

参数的存在足以告诉CoffeeScript您要执行该函数而不是获取对它的引用。