Backbone.js 带Q承诺问题的主干模型

Backbone.js 带Q承诺问题的主干模型,backbone.js,modal-dialog,promise,q,Backbone.js,Modal Dialog,Promise,Q,我们有一种方法(onOpenNotitiesClicked)用于显示输入注释的模式视图。我们已经为此()实现了主干模式插件 有两种情况: 后端中还没有注释:初始化并呈现 模态 后端中已经有注释=>请先收集它们,然后 然后将注释传递给模态(初始化),然后进行渲染 在第一种情况下,它工作得很好!显示模式。 在第二种情况下,未显示模态 我已经调试了这两种情况,在这两种情况下,都执行了所有方法,在元素中,我看到了模态视图的HTML 我怀疑这个在Q/promise数据获取过程中丢失了一些数据,但我看不出

我们有一种方法(
onOpenNotitiesClicked
)用于显示输入注释的模式视图。我们已经为此()实现了主干模式插件

有两种情况:

  • 后端中还没有注释:初始化并呈现
    模态

  • 后端中已经有注释=>请先收集它们,然后 然后将注释传递给模态(初始化),然后进行渲染

  • 在第一种情况下,它工作得很好!显示模式。
    在第二种情况下,未显示模态
    我已经调试了这两种情况,在这两种情况下,都执行了所有方法,在元素中,我看到了模态视图的HTML

    我怀疑
    这个
    在Q/promise数据获取过程中丢失了一些数据,但我看不出是什么/在哪里/如何/为什么

    有人知道我做错了什么吗?或者我错过了什么

    模态的创建:

        onOpenNotitieClicked: function (event) {
            var $element, taak, taakId, id, options = {};
    
            $element = this.$(event.currentTarget).closest("li");
            id = $element.data("id");
            taakId = $element.data("taak-id");
            taak = this.getCurrentTask(event);
    
            options.taakKey = id;
            options.taakId = taakId;
            options.heeftNotities = taak.heeftNotities;
            options.datacontroller = this.datacontroller;
            this.notitiesOptions = options;
            // this.renderNotitieModal(options);
            if (taak.heeftNotities) {
                this.getActiviteitNotities(taakId).then(_.bind(this.onSuccessGetNotities, this), _.bind(this.onErrorGetNotities, this));
            } else {
                this.renderNotitieModal(this.notitiesOptions);
            }
    
        },
    
    如果需要收集笔记:

        getActiviteitNotities: function (taakId) {
            return this.datacontroller.getNotities(taakId);
        },
    
        onSuccessGetNotities: function (notities) {
            this.notitiesOptions.notities = notities;
            this.renderNotitieModal(this.notitiesOptions);
        },
    
        onErrorGetNotities: function () {
            this.renderNotitieModal(this.notitiesOptions);
        },
    
    为了从后端获取注释,使用Q/promises

        getNotities: function (taakId, refresh, klantorderId) {
            return Q.promise(function (resolve, reject) {
                var options = {};
    
                if (!this.notitiesCollection || this.taakId !== taakId || refresh) {
                    delete this.notitiesCollection;
    
                    this.notitiesCollection = this.createCollection("NotitiesCollection", {
                        id: this.taakId,
                        resource: this.NOTITIES_RESOURCE
                    });
    
                    if (taakId) {
                        this.taakId = taakId;
    
                        options = {
                            data: {
                                parentId: this.taakId
                            }
                        };
                    } else if (klantorderId) {
    
                        options = {
                            data: {
                                klantorderId: klantorderId
                            }
                        };
                    }
    
                    resolve(this.notitiesCollection.fetch(options));
                } else if (this.notitiesCollection) {
                    resolve(this.notitiesCollection.toJSON());
                } else {
                    reject("ERROR");
                }
            }.bind(this));
        },
    
    Notities.js(模态视图):

    (function () {
    "use strict";
    
    App.Bewaking.modals.BewakingNotitieModal = Backbone.Modal.extend({
        template: JST.bewaking_notitie_modal, //jshint ignore:line
        title: "Notities",
        formatter: new App.Main.helpers.Formatter(),
    
        events: {
            "click #save-notitie": "onSaveNotitieClicked"
        },
    
        initialize: function (options) {
            this.taakId = options.taakId;
            this.taakKey = options.taakKey;
            this.datacontroller = options.datacontroller;
            this.notities = options.notities;
        },
    
        afterRender: function () {
            console.log("afterRender");
            this.$notitieModal = this.$("#notitieModal");
            this.$nieuweNotitie = this.$("#nieuwe-notitie");
            this.$notitieErrorTekst = this.$("#notitie-error-tekst");
    
            this.$notitieModal.on("shown.bs.modal", function () {
                this.$nieuweNotitie.focus();
            }.bind(this));
        },
    
        render: function () {
            console.log(this.notities);
            this.$el.html(this.template({
                formatter: this.formatter,
                notities: this.notities
            }));
    
            return this;
        }
     });
    }());