javascript - Ember 附加 RESTadaptor : error on <Ember. Route:ember325>/加载路由时出错,然后大量转储 JavaScript

标签 javascript json rest ember.js ember-data

我是 Ember 新手,在从 Fixture Adapter 迁移到 REST Adapter 时遇到了这个巨大且有些神秘的错误。除了注释掉我的装置数据之外,没有进行其他代码更改。

我的代码:

App = Ember.Application.create();

// App.ApplicationAdapter = DS.FixtureAdapter.extend();

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'http://192.168.1.193:8080',
  namespace: '/serviceprovidersservice/rest'
});

App.Router.map(function() {
  this.resource("service_providers", function() {
    this.route("new");
    this.route("edit", { path: 'edit/:id' });
  });

  this.resource("customers", function() {
    this.route("new");
    this.route("edit", { path: 'edit/:id' });
  });
});

// Routes

App.ServiceProvidersIndexRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('ServiceProvider');
    }
});

App.ServiceProvidersNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('ServiceProvider');
    }
});

App.ServiceProvidersEditRoute = Ember.Route.extend({
    model: function(params) {
        return this.store.find('ServiceProvider', params.id);
    }
});

App.CustomersIndexRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('Customer');
    }
});

App.CustomersEditRoute = Ember.Route.extend({
    model: function(params) {
        return this.store.find('Customer', params.id);
    }
});

App.CustomersNewRoute = Ember.Route.extend({
    model : function() {
        return {
            serviceproviders : this.store.find('ServiceProvider')
        };
    }
})

// Controllers

App.ServiceProvidersNewController = Ember.ObjectController.extend({
    actions : {
        create: function() {
            name = this.get("name");
            if (!name.trim()) { return; }
            email = this.get("email");

            sp = this.store.createRecord('ServiceProvider', {
                name: name,
                email: email
            });
            sp.save();
            this.set('name', '');
            this.set('email', '');
            this.transitionToRoute("service_providers.edit", sp);
        }
    }
});

App.ServiceProvidersEditController = Ember.ObjectController.extend({
    isEditing: false,
    actions: {
        edit: function() {
            this.set('isEditing', true);
        },
        doneEditing: function() {
            this.set('isEditing', false);
            this.get('model').save();
        }
    }
});

App.CustomersEditController = Ember.ObjectController.extend({
    isEditing: false,
    actions: {
        edit: function() {
            this.set('isEditing', true);
        },
        doneEditing: function() {
            this.set('isEditing', false);
            this.get('model').save();
        }
    }
});

App.CustomersNewController = Ember.ObjectController.extend({
    selectedServiceProvider : null,
    actions : {
        create: function() {
            firstname = this.get("firstname");
            lastname = this.get("lastname");
            if (!firstname.trim()) { return; }
            email = this.get("email");
            serviceprovider = this.get("selectedServiceProvider");
            sp = this.store.createRecord('Customer', {
                firstname: firstname,
                lastname: lastname,
                email: email,
                serviceprovider: serviceprovider
            });
            sp.save();
            this.set('name', '');
            this.set('email', '');
            this.transitionToRoute("customers.edit", sp);
        }
    }
});

// Models

App.Customer = DS.Model.extend({
    serviceprovider: DS.belongsTo('serviceProvider'),
    firstname: DS.attr('string'),
    lastname: DS.attr('string'),
    email: DS.attr('string')
});

App.ServiceProvider = DS.Model.extend({
    name: DS.attr('string'),
    email: DS.attr('string'),
    customers: DS.hasMany('customer', {async:true})
});

错误:

[15:46:25.144] DEPRECATION: Action handlers contained in an `events` object are deprecated in favor of putting them in an `actions` object (error on <Ember.Route:ember325>)
    trigger@file:///home/zen/ember/js/libs/ember-1.0.0.js:29641
    handleError@file:///home/zen/ember/js/libs/ember-1.0.0.js:29903
    invokeCallback@file:///home/zen/ember/js/libs/ember-1.0.0.js:8055
    Promise.prototype.then/<@file:///home/zen/ember/js/libs/ember-1.0.0.js:8109
    EventTarget.trigger@file:///home/zen/ember/js/libs/ember-1.0.0.js:7878
    reject/<@file:///home/zen/ember/js/libs/ember-1.0.0.js:8180
    DeferredActionQueues.prototype.flush@file:///home/zen/ember/js/libs/ember-1.0.0.js:5459
    Backburner.prototype.end@file:///home/zen/ember/js/libs/ember-1.0.0.js:5545
    Backburner.prototype.run@file:///home/zen/ember/js/libs/ember-1.0.0.js:5584
    Ember.run@file:///home/zen/ember/js/libs/ember-1.0.0.js:5915
    Ember.EventDispatcher<._bubbleEvent@file:///home/zen/ember/js/libs/ember-1.0.0.js:19034
    Ember.EventDispatcher<.setupHandler/</<@file:///home/zen/ember/js/libs/ember-1.0.0.js:18978
    Ember.handleErrors@file:///home/zen/ember/js/libs/ember-1.0.0.js:555
    Ember.EventDispatcher<.setupHandler/<@file:///home/zen/ember/js/libs/ember-1.0.0.js:18984
    jQuery.event.dispatch@file:///home/zen/ember/js/libs/jquery-1.9.1.js:3074
    jQuery.event.add/elemData.handle@file:///home/zen/ember/js/libs/jquery-1.9.1.js:2750
[15:46:25.144] Error while loading route: ({readyState:0, getResponseHeader:(function ( key ) {
                    var match;
                    if ( state === 2 ) {
                        if ( !responseHeaders ) {
                            responseHeaders = {};
                            while ( (match = rheaders.exec( responseHeadersString )) ) {
                                responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
                            }
                        }
                        match = responseHeaders[ key.toLowerCase() ];
                    }
                    return match == null ? null : match;
                }), getAllResponseHeaders:(function () {
                    return state === 2 ? responseHeadersString : null;
                }), setRequestHeader:(function ( name, value ) {
                    var lname = name.toLowerCase();
                    if ( !state ) {
                        name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
                        requestHeaders[ name ] = value;
                    }
                    return this;
                }), overrideMimeType:(function ( type ) {
                    if ( !state ) {
                        s.mimeType = type;
                    }
                    return this;
                }), statusCode:(function ( map ) {
                    var code;
                    if ( map ) {
                        if ( state < 2 ) {
                            for ( code in map ) {
                                // Lazy-add the new callback in a way that preserves old ones
                                statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
                            }
                        } else {
                            // Execute the appropriate callbacks
                            jqXHR.always( map[ jqXHR.status ] );
                        }
                    }
                    return this;
                }), abort:(function ( statusText ) {
                    var finalText = statusText || strAbort;
                    if ( transport ) {
                        transport.abort( finalText );
                    }
                    done( 0, finalText );
                    return this;
                }), state:(function () {
                    return state;
                }), always:(function () {
                    deferred.done( arguments ).fail( arguments );
                    return this;
                }), then:null, promise:(function ( obj ) {
                    return obj != null ? jQuery.extend( obj, promise ) : promise;
                }), pipe:(function ( /* fnDone, fnFail, fnProgress */ ) {
                    var fns = arguments;
                    return jQuery.Deferred(function( newDefer ) {
                        jQuery.each( tuples, function( i, tuple ) {
                            var action = tuple[ 0 ],
                                fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
                            // deferred[ done | fail | progress ] for forwarding actions to newDefer
                            deferred[ tuple[1] ](function() {
                                var returned = fn && fn.apply( this, arguments );
                                if ( returned && jQuery.isFunction( returned.promise ) ) {
                                    returned.promise()
                                        .done( newDefer.resolve )
                                        .fail( newDefer.reject )
                                        .progress( newDefer.notify );
                                } else {
                                    newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
                                }
                            });
                        });
                        fns = null;
                    }).promise();
                }), done:(function () {
                if ( list ) {
                    // First, we save the current length
                    var start = list.length;
                    (function add( args ) {
                        jQuery.each( args, function( _, arg ) {
                            var type = jQuery.type( arg );
                            if ( type === "function" ) {
                                if ( !options.unique || !self.has( arg ) ) {
                                    list.push( arg );
                                }
                            } else if ( arg && arg.length && type !== "string" ) {
                                // Inspect recursively
                                add( arg );
                            }
                        });
                    })( arguments );
                    // Do we need to add the callbacks to the
                    // current firing batch?
                    if ( firing ) {
                        firingLength = list.length;
                    // With memory, if we're not firing then
                    // we should call right away
                    } else if ( memory ) {
                        firingStart = start;
                        fire( memory );
                    }
                }
                return this;
            }), fail:(function () {
                if ( list ) {
                    // First, we save the current length
                    var start = list.length;
                    (function add( args ) {
                        jQuery.each( args, function( _, arg ) {
                            var type = jQuery.type( arg );
                            if ( type === "function" ) {
                                if ( !options.unique || !self.has( arg ) ) {
                                    list.push( arg );
                                }
                            } else if ( arg && arg.length && type !== "string" ) {
                                // Inspect recursively
                                add( arg );
                            }
                        });
                    })( arguments );
                    // Do we need to add the callbacks to the
                    // current firing batch?
                    if ( firing ) {
                        firingLength = list.length;
                    // With memory, if we're not firing then
                    // we should call right away
                    } else if ( memory ) {
                        firingStart = start;
                        fire( memory );
                    }
                }
                return this;
            }), progress:(function () {
                if ( list ) {
                    // First, we save the current length
                    var start = list.length;
                    (function add( args ) {
                        jQuery.each( args, function( _, arg ) {
                            var type = jQuery.type( arg );
                            if ( type === "function" ) {
                                if ( !options.unique || !self.has( arg ) ) {
                                    list.push( arg );
                                }
                            } else if ( arg && arg.length && type !== "string" ) {
                                // Inspect recursively
                                add( arg );
                            }
                        });
                    })( arguments );
                    // Do we need to add the callbacks to the
                    // current firing batch?
                    if ( firing ) {
                        firingLength = list.length;
                    // With memory, if we're not firing then
                    // we should call right away
                    } else if ( memory ) {
                        firingStart = start;
                        fire( memory );
                    }
                }
                return this;
            }), complete:(function () {
                if ( list ) {
                    // First, we save the current length
                    var start = list.length;
                    (function add( args ) {
                        jQuery.each( args, function( _, arg ) {
                            var type = jQuery.type( arg );
                            if ( type === "function" ) {
                                if ( !options.unique || !self.has( arg ) ) {
                                    list.push( arg );
                                }
                            } else if ( arg && arg.length && type !== "string" ) {
                                // Inspect recursively
                                add( arg );
                            }
                        });
                    })( arguments );
                    // Do we need to add the callbacks to the
                    // current firing batch?
                    if ( firing ) {
                        firingLength = list.length;
                    // With memory, if we're not firing then
                    // we should call right away
                    } else if ( memory ) {
                        firingStart = start;
                        fire( memory );
                    }
                }
                return this;
            }), success:(function () {
                if ( list ) {
                    // First, we save the current length
                    var start = list.length;
                    (function add( args ) {
                        jQuery.each( args, function( _, arg ) {
                            var type = jQuery.type( arg );
                            if ( type === "function" ) {
                                if ( !options.unique || !self.has( arg ) ) {
                                    list.push( arg );
                                }
                            } else if ( arg && arg.length && type !== "string" ) {
                                // Inspect recursively
                                add( arg );
                            }
                        });
                    })( arguments );
                    // Do we need to add the callbacks to the
                    // current firing batch?
                    if ( firing ) {
                        firingLength = list.length;
                    // With memory, if we're not firing then
                    // we should call right away
                    } else if ( memory ) {
                        firingStart = start;
                        fire( memory );
                    }
                }
                return this;
            }), error:(function () {
                if ( list ) {
                    // First, we save the current length
                    var start = list.length;
                    (function add( args ) {
                        jQuery.each( args, function( _, arg ) {
                            var type = jQuery.type( arg );
                            if ( type === "function" ) {
                                if ( !options.unique || !self.has( arg ) ) {
                                    list.push( arg );
                                }
                            } else if ( arg && arg.length && type !== "string" ) {
                                // Inspect recursively
                                add( arg );
                            }
                        });
                    })( arguments );
                    // Do we need to add the callbacks to the
                    // current firing batch?
                    if ( firing ) {
                        firingLength = list.length;
                    // With memory, if we're not firing then
                    // we should call right away
                    } else if ( memory ) {
                        firingStart = start;
                        fire( memory );
                    }
                }
                return this;
            }), status:0, statusText:"[Exception... \"Access to restricted URI denied\"  code: \"1012\" nsresult: \"0x805303f4 (NS_ERROR_DOM_BAD_URI)\"  location: \"file:///home/zen/ember/js/libs/jquery-1.9.1.js Line: 8526\"]"})
[15:46:25.156] uncaught exception: [object Object]

我知道这与端点或输入的 JSON 无关,因为 Ember 甚至没有尝试发出 HTTP 请求。我被这个问题难住了。

最佳答案

这里的罪魁祸首是错误消息的末尾:

访问受限 URI 被拒绝

这可能是因为您正在运行 file:// 协议(protocol)。您应该找到一种使用 http:// 访问 Ember 应用程序的方法,例如http://localhost:8080/

请注意,如果您的 AJAX 端点与该页面的主机不同,则需要设置 CORS header 。因此,您可能需要更改适配器,不指定 host: 属性(应默认为当前主机)。

关于javascript - Ember 附加 RESTadaptor : error on <Ember. Route:ember325>/加载路由时出错,然后大量转储 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19130753/

相关文章:

javascript - 通过更改内容找到 div 的最小高度,这样下面的页面就不会跳来跳去

javascript - Safari 中的随机行?

javascript - 客户端解析 TIF 文件

ios - 从 JSON 中获取对象

node.js - REST API 的 Flash 消息

javascript - mobx中如何实现数组的浅拷贝

javascript - 从两个数组创建 JSON 对象

json - Jackson:有没有办法将 POJO 直接序列化为 treemodel?

ios - 为什么我无法快速下载所有 json 值?

forms - http.Request r.FormValue 什么都不返回/map[]