0

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

我的代码:

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 请求。我被这个难住了。

4

1 回答 1

2

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

Access to restricted URI denied

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

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

于 2013-10-02T06:45:23.287 回答