0

コンテンツ ビューの div を次のようにクリーンアップします。

$(".box2").empty(); 

その後、次のビューをレンダリングします (モデルを削除せずに)。最後のビューに多くのコンテンツがあった場合、次のビューをロードすると、最後のビューの残りがまだしばらく表示されます。
この問題をどのように解決できますか?

コード:

    var Contents = Backbone.View.extend({
        el: "body", 
        events: {
            "click .addAll": "addContentAll", "click .addFront": "addContentChart"    
        },
        initialize: function() {
            _.bindAll(this); 
            this.model = new ContentCollection();
            this.model.on("add", this.contentAdded);
        },          
        addContentAll: function(event) {
                    this.model.add({name: "all"});  
                    //some content or plugin
        },  
        addContentChart: function(event) {
                    this.model.add({name: "chart"});
                    //charts content
        },         
        contentAdded: function(content) {
            if (content.view == null) {
                var template_name;              
                switch(content.get("name")){        
                    case 'all': template_name = 'all'; break; 
                    case 'chart': template_name = 'chart'; break;  
                }                                       
                content.view = new ContentView({model: content,template: $.trim($("[data-template-name='"+ template_name +"'] div").html() || "Template not found!")});
                $(".box2").empty(); 
                this.$el.find(".content").find("div.box2").append(content.view.render().el);                                                 
            }       
        }   
   });
var ContentView = Backbone.View.extend({
            tagName: "div",
            template: null,
            initialize: function() {
                _.bindAll(this);
                this.template = this.options.template; 
            },
            render: function() {        
                this.$el.html(Mustache.render(this.template, this.model.toJSON())); 
                return this; 
            }
 });     
 var view = new Contents();

empty()コンテンツがレンダリングされた後。empty()関数がいつ作成されたかを確認する方法はありますか? voidを返すと思います。ローディング インジケーターを使用してビューをレンダリングするのは良い方法です。

解決済み: コンテンツの別のプラグインで競合が発生しました。

4

1 に答える 1

1

divをクリアするという質問に対する直接の答えではありませんが、同じ場所に別のdivを作成することでパフォーマンスを向上できるかどうかをテストしましたか(つまり、<div id = "imHidden"> </ div> <div id = "imVisible"> </ div>)、まだ非表示になっている間に入力してから、2つのdivのそれぞれで非表示/表示状態を切り替えますか?

これがUI内で頻繁に行う必要がある場合は、2つのdivを切り替えることもできます。1つは表示され、もう1つは表示されず、divを埋めたり空にしたりする操作は、現在非表示になっている方でのみ実行されます。

于 2013-01-22T13:55:19.613 に答える