1

timeagoまたはeasydate<time class="prettydate"><%= created_at %></time>"(このようなものを出力する)にどのように適用しますMon Jun 18 03:46:27 +0000 2012か?

以下を試しましたが、バックボーン/アンダースコアを使用して日付をレンダリングしているため、機能しません。

$(function() {
  $('time.prettydate').easydate();
});

これが私の見解です:

( function ( views ){

    views.ResultView = Backbone.View.extend({
        tagName : 'li',
        template: _.template($('#resultItemTemplate').html()),

        initialize: function() {
            this.model.bind('change', this.render, this);
            this.model.bind('destroy', this.remove, this);
        },

        render : function () {
            //this.$el.html(this.template(this.model.toJSON()));
            var html = this.template(this.model.toJSON());
            this.$el.html($(html).timeago());
        }
    });

})( app.views );
4

1 に答える 1

4

おそらく、ビューには次のようなものがあります。

render: function() {
    var html = _.template(...);
    this.$el.append(html);
    return this;
}

あなたがする必要があるのは、プラグインをhtml追加している間にプラグインを直接適用することだけです:

render: function() {
    var html = _.template(...);
    this.$el.append($(html).timeago());
    return this;
}

デモ: http://jsfiddle.net/ambiguous/Fk6xF/

を行っている場合、これは同様にうまく機能しますthis.$el.html(...)

timeago を適用する必要がある部分がテンプレート.timeago()にある場合は、それらを探し出して個別に適用する必要があります。このような何かがうまくいくはずです:

render: function() {
    var html = _.template(...);
    this.$el.html(html);
    this.$el.find('.timeago').timeago(); // Assuming you're using class="timeago"
    return this;
}

デモ: http://jsfiddle.net/ambiguous/dHr6D/

于 2012-06-21T22:54:58.537 に答える