骨干网创建不等待json被传递(Guid未定义)

Backbone create does not wait for json to be passed (Guid is undefined)

本文关键字:Guid 未定义 创建 等待 json 骨干网      更新时间:2023-09-26

在一个项目中,我最近不再使用myVar[0]。Key;使用myVar.WhatEver;这搞砸了一些事情,因为现在我的.create不等待Web服务响应请求,这意味着当我尝试呈现创建的帖子时,像"Guid"这样的变量,在我的情况下还有"Name",不会传递给模板。

我的代码(有些修改了;变量名与原始代码不匹配):

var self = this;
var variableNames = this.options.variableNames;
variableNames.create({
            variable1: values.variable1,
            variable2: values.variable2,
            variable3: values.variable3 //And so on...
        }, {
            wait: true,
            success: function(variableName) {
                // Update nav menu list
                $('#nav').someJqueryMagic()
                      .text(variableName.get('Name'))
                      .data('variableName', variableName.get('Guid')) //This does not work. It is undefined by some reason!
                )); //This code adds a menu item
                //Call function for triggering the custom event, pass in the variableName object
                self.createSuccess(variableName);
                self.modal.close();
                new Interface.Message().success('OK! Du har skapat ett nytt objekt.'); //Swedish rules
            },
            error: function() {
                new Interface.Message().error('Det gick inte att skapa objektet.');
            }
        });
    },
    createSuccess: function(variableName) {
        //Trigger event for rendering the new entry
        this.vent.trigger('variableName:created', variableName);
        //This ends up with a table row is rendered. The variableName 
        //object contains Name of who has created the post, a Guid, and 
        //some other information.
    }

当我调试代码时,发送的请求在创建完成之前不会回复json对象->我想太晚了?你知道发生了什么吗?

错误发生在后端代码中,而不是前端。在后端的某个地方,我们触发了对请求的200 OK响应,这反过来又触发了.create()的成功。我不知道在哪里或如何,但我们通过恢复一些新编写的代码来修复它。