Ember-data一直在说"没有找到mdel"

时间:2014-11-21 00:23:55

标签: ember.js coffeescript requirejs ember-data

我正在尝试使用Ember-Data编写EMberjs应用程序。还有,require.js和coffeescript。尽管遵循了我能找到的每一个指南和讨论,我仍然得到'没有找到'错误的模型。

这是我的课程:

main.coffee(require.js的入口点):

require.config
  paths:
    jQuery:     "../javascript/jquery-2.1.1.min"
    handlebars: "../javascript/handlebars-v1.3.0"
    ember:      "../javascript/ember.prod"
    ember_data: "../javascript/ember-data.prod",
  shim:
    ember:
         deps: ["jQuery", "handlebars"]
         exports: "Ember"
    'ember_data':
      deps:[ 'ember'],
      exports:'DS'

require ["app", "router"], (app, Router) ->
  app.deferReadiness()
  Router()
  app.advanceReadiness()
  return

app.coffee:

define "app", ["ember", "ember_data"], (Ember) ->
  window.app = Ember.Application.create()
  app.ApplicationAdapter = DS.FixtureAdapter.extend()
  app

router.coffee:

define "router", ["app", "ember-data", "ember", "models/person"], (app) ->
  ->         
    app.Router.map -> 
      @route 'home', path: "/"
      @resource('person', { path: 'person'},  ->
        @route('details', { path: ':slug' })
        return
      )
      return
    app.HomeRoute = Ember.Route.extend 
      model: ->

    app.PersonRoute = Ember.Route.extend 
      model: () ->
        return @store.find("Person")

模型/ person.coffee:

class app.Person extends DS.model
  first: DS.attr("string") 

app.Person.FIXTURES = { person: [
       {
        id: 1, 
        first: "first_1"
       },
       {
        id: 2, 
        first: "first_2"
       }
  ]}

但是当我去http://localhost:9000/#/person,时,我得到了这个:

Error while processing route: person.index" "No model was found for 'Person'" "EmberError@http://localhost:9000/assets/javascript/ember.prod.js:13949:17
Store<.modelFor@http://localhost:9000/assets/javascript/ember-data.prod.js:11264:1
Store<.findAll@http://localhost:9000/assets/javascript/ember-data.prod.js:10845:20
Store<.find@http://localhost:9000/assets/javascript/ember-data.prod.js:10476:1
app.PersonRoute<.model@http://localhost:9000/assets/javascript/router.js:24:16
apply@http://localhost:9000/assets/javascript/ember.prod.js:19296:1
superWrapper@http://localhost:9000/assets/javascript/ember.prod.js:18867:15
Route<.deserialize@http://localhost:9000/assets/javascript/ember.prod.js:24467:16
applyHook@http://localhost:9000/assets/javascript/ember.prod.js:45215:16
HandlerInfo.prototype.runSharedModelHook@http://localhost:9000/assets/javascript/ember.prod.js:43237:22
UnresolvedHandlerInfoByParam<.getModel@http://localhost:9000/assets/javascript/ember.prod.js:43463:16
bind/<@http://localhost:9000/assets/javascript/ember.prod.js:45089:16
tryCatch@http://localhost:9000/assets/javascript/ember.prod.js:45538:16
invokeCallback@http://localhost:9000/assets/javascript/ember.prod.js:45550:17
publish@http://localhost:9000/assets/javascript/ember.prod.js:45521:11
@http://localhost:9000/assets/javascript/ember.prod.js:28956:9
DeferredActionQueues.prototype.invoke@http://localhost:9000/assets/javascript/ember.prod.js:679:11
DeferredActionQueues.prototype.flush@http://localhost:9000/assets/javascript/ember.prod.js:749:15
Backburner.prototype.end@http://localhost:9000/assets/javascript/ember.prod.js:135:11
createAutorun/backburner._autorun<@http://localhost:9000/assets/javascript/ember.prod.js:521:9
" ember.prod.js:15069

任何人都有想法吗?

编辑: 好像我将person.coffee文件从/ models移动到与main和App相同的级别,并相应地更改路由器中的'define'行,它按预期工作。对我来说还是一个谜:(

2 个答案:

答案 0 :(得分:0)

我不是百分百确定,但问题可能出在App.Person的格式错误的灯具上。

你能改写像这样的灯具吗?

app.Person.FIXTURES = [
   {
    id: 1, 
    first: "first_1"
   },
   {
    id: 2, 
    first: "first_2"
   }
]

答案 1 :(得分:0)

你应该使用reopenClass定义你的灯具,所以沿着这些方向:

App.Documenter.reopenClass({
  FIXTURES: [
    { id: 1, firstName: 'Trek', lastName: 'Glowacki' },
    { id: 2, firstName: 'Tom' , lastName: 'Dale'     }
  ]
});

如此处示例中所示http://emberjs.com/guides/models/the-fixture-adapter/

您使用的方法已过时。