EmberJS控制台错误-加载路由时出错:未定义

EmberJS console error- Error while loading route: undefined

本文关键字:出错 未定义 路由 加载 控制台 错误 EmberJS      更新时间:2023-09-26

我是EmberJS的初学者。如果你能详细解释一下就太好了。我有一个获取产品的api端点,它期望将GET请求发送到以下url-

/api/products?date=2014-09-16&meal_type=2

这里,date和meal_type是查询参数。我的router.js看起来像这样-

    App.Router.map(function() {
      this.resource('products', { path: '/products/date/:date/meal/:mealType'} );
    });
    App.Router.reopen({
      location: 'history'
    });

这种动态路由的原因是我的应用程序的url似乎是相同的格式。

routes/product.js看起来像-

    App.ProductsRoute = Ember.Route.extend({
      model: function(params) {
        return this.store.findQuery('product', {date: params.date, meal_type: params.mealType});
    },
      queryParams: {
        date: {
          refreshModel: true
        },
        mealType: {
          refreshModel: true
        }
      },

});

controller/products_controller.js

    App.ProductsController = Ember.ArrayController.extend({
      queryParams: ['date', 'meal_type'],
      date: null,
      meal_type: null,
      products: function() {
        return this.get('model.content');
      }.property()

我在浏览器控制台上得到一个错误-

Error while loading route: undefined

这似乎在ember.js行?body=1:3522.

如有任何帮助,我们将不胜感激。感谢

在对错误进行了大量研究后,我发现了数据库中的不一致性。我通过恢复一致的数据库转储解决了这个错误。

结论:EmberJS希望数据保持一致。否则,它可能会引发难以调试的错误。