2

完全なサンプルはこちら

私は非常に単純なバックボーン js 構造を持っています。

    var Step1View = Backbone.View.extend({
    el:'.page',
    render:function () {
        var template = _.template($('#step1-template').html());
        this.$el.html(template);

    }
});

var step1View = new Step1View();
var Router = Backbone.Router.extend({
    routes:{
        "":"home"
    }
});

var router = new Router;
router.on('route:home', function () {
    step1View.render();
})
Backbone.history.start();

これはうまくいきますが、この単純な jquery 関数を呼び出すことができません。

$(document).ready(function() { $('.tip').tooltip(); });

アップデート

ここで男子生徒のエラー。Jquery onload 関数をルートに配置する必要があります。私はバックボーンに非常に慣れていないので、これがベストプラクティスかどうかわかりません。しかし、次の作品。

            render:function () {

            var that = this;
            var savings = new Savings();
            savings.fetch({
                success:function () {
                    var template = _.template($('#step3-template').html(), {savings:savings.models});
                    that.$el.html(template);
// put your jquery good ness here
                    $('.tip').tooltip();
                    $(".step3-form").validate();
                }
            })

        }
4

2 に答える 2

2

答えが見つかったようです。代わりにこれを行うことで、jQuery を少しスコープダウンできることも共有したかっただけです。

        savings.fetch({
            success:function () {
                var template = _.template($('#step3-template').html(), {savings:savings.models});
                that.$el.html(template);
                that.$el.find('.tip').tooltip();
                that.$el.find(".step3-form").validate();
            }

tip例にあるものは機能しますが、作成したばかりの要素を使用してその内部で作成したヒントのみを下方向にスキャンできるクラスを使用して、HTML のドキュメント全体を毎回スキャンしています。わずかな最適化。

これが役に立てば幸いです!

于 2012-12-18T21:11:39.533 に答える