Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Js应用程序重新加载,调用render两次_Javascript_Backbone.js - Fatal编程技术网

Javascript Js应用程序重新加载,调用render两次

Javascript Js应用程序重新加载,调用render两次,javascript,backbone.js,Javascript,Backbone.js,我已经扩展了todomvc的主干版本,我发现视图非常易变。难以消除听众和事件的歧义。不明白为什么会调用两次app.AppView.render()render,而在第二次调用时,本地存储中的项会被丢弃。有人对本地主干存储有问题吗 搜索输入存储第一个项目,然后重新加载某些内容,集合为空 Html视图: app.AppView = Backbone.View.extend({ el: '#searchapp', events: { 'keypress #new-sea

我已经扩展了todomvc的主干版本,我发现视图非常易变。难以消除听众和事件的歧义。不明白为什么会调用两次
app.AppView.render()
render,而在第二次调用时,本地存储中的项会被丢弃。有人对本地主干存储有问题吗

搜索输入存储第一个项目,然后重新加载某些内容,集合为空

Html视图:

app.AppView = Backbone.View.extend({
    el: '#searchapp',
    events: {
        'keypress #new-search': 'createOnEnter',
        'click #clear-unstarred': 'clearUnStarred',
    },
    initialize: function () {
        this.$input = this.$('#new-search');
        this.$list = $('#search-list');
        this.$results = this.$('#search-grids');
        this.$stats = this.$('#search-stats');

        this.listenTo(app.searches, 'add', this.addOne);
        this.listenTo(app.searches, 'reset', this.addAll);
        this.listenTo(app.searches, 'change:starred', this.filterOne);
        this.listenTo(app.searches, 'filter', this.filterAll);
        this.listenTo(app.searches, 'all', this.render);

        app.searches.fetch(); //{reset: true}
    },

    render: function () {
        //app.SearchFilter = app.SearchFilter || 'starred';
        var starred = app.searches.starred().length;
        var remaining = app.searches.remaining().length;
        if (app.searches.length) {

            var h = $('#stats-template').html(), t = _.template(h),
                d = {
                    count: (starred + remaining),
                    starred: starred,
                    remaining: remaining
                }, s = t(d);

            this.$stats.html(s);
            this.$('#filters a').removeClass('selected').filter('[href="#/' + (app.SearchFilter || '') + '"]').addClass('selected');
            app.searches.last().trigger('runsearch');

        } else {
            //this.$results.hide();
            //this.$stats.hide();
        }

    }, ...............
项目的视图:

app.SearchView = Backbone.View.extend({
    tagName:  'div',

    events: {
        'click .do-search': 'runSearch',
        'click .do-destroy': 'clear',
        'click .do-toggle-star': 'togglestar',
        'dblclick label': 'edit',
        'keypress input.title': 'updateOnEnter',
        'keydown input.title': 'revertOnEscape',
        'blur input.title': 'close'
    },

    initialize: function () {
        this.$results = $('#search-grids');
        this.listenTo(this.model, 'change', this.render);
        this.listenTo(this.model, 'destroy', this.remove);
        this.listenTo(this.model, 'visible', this.toggleVisible);
        this.listenTo(this.model, 'runsearch', this.runSearch);
    },

    render: function () {
        if (this.model.changed.id !== undefined) {
            return;
        }
        var h = $('#search-item-template').html(), t = _.template(h),
            d = this.model.toJSON(), s = t(d);
        this.$el.html(s);
        this.$el.toggleClass('starred', this.model.get('starred'));
        this.$input = this.$('input.title');
        this.toggleVisible();
        return this;
    },

`

Chrome开发者工具在发布期间未显示“存储”。清理确实有帮助。没有做出重大改变。基本上确保在此处执行集合add()和model save()


找到了此网站上的相关帖子。主干。本地存储在保存时分配id,触发更改事件。仍然是我重新加载和本地存储为空的原因。******