douzhu5900 2013-11-17 08:53
浏览 55
已采纳

关闭后重新渲染视图

define([
    'jquery',
    'underscore',
    'backbone',
    'collections/jobs',
    'text!templates/jobs/list.html'
], function($, _, Backbone, JobCollection, JobListTemplate){
    var JobWidget = Backbone.View.extend({
        el: '#bbJobList',
        initialize: function () {
            _.bindAll(this, 'detect_scroll');
            $(window).scroll(this.detect_scroll);
            this.isLoading = false;
            this.jobCollection = new JobCollection();
        },
        render: function () {
            this.loadResults();
        },
        loadResults: function () {
            var that = this;
            // we are starting a new load of results so set isLoading to true
            this.isLoading = true;

            this.jobCollection.fetch({
                success: function (jobs) {

                    $(that.el).append(_.template(JobListTemplate, {jobs: jobs.models, _:_}));
                    // Now we have finished loading set isLoading back to false
                    that.isLoading = false;
                }
            });
        },
        close: function(){
            this.remove();
            this.unbind();
        }
    });
    return JobWidget;
});

How do i remove RELOAD render after i close it? I'm planning to Re-Render , the update data are in model which i will grab out from controller(If it's possible)

I tried

this.render() 
  • 写回答

1条回答 默认 最新

  • douguan3470 2013-11-17 11:26
    关注

    if you are planning to re-render the view you shouldn't assign el to the prototype, like el: '#bbJobList'.

    While instantiating the view, append view to the element like

     var view = new JobWidget();
     view.render();
     view.$el.appendTo('#bbJobList');
    

    after closing view which remove view from the DOM, to re-render the view, instantiate it again as above.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口