0

我的 router.js 是这样的:

@resource 'movies' , ->
  @route 'free'
  @route 'featured'
  @route 'favorites' , path: '/favorites'
  @route 'movie', path: '/:movie'

@resource 'seasons' , ->
  @route 'free'
  @resource 'seasons.featured',  { path: '/featured' } ,  ->
    @route 'season', path : '/:season'
  @route 'index'
  @route 'season', path: '/:season'

示例:我访问 :/movies/free ,我希望ember-data请求:

/movies/free.json 

但不是这样,它要求:

/movies.json

似乎ember-data忽略了任何嵌套的 url。

知道我做错了什么吗?

更新

我必须自定义我的 store.js,但我认为这些更改不是问题的一部分

 App.Adapter = DS.RESTAdapter.extend({
  //bulkCommit: false , // encadena las llamadas a la API, no creo que la nuestra lo soporte asi que lo quito
  url: 'xxxxxxxxx',   //  especifico la url sobre la que tirar las peticiones
  buildURL: function(record, suffix) {  //add .json to the request, wihtout this, it calls api.com/movies.json and now , api.com/movies.json . Our api needs the second way :D
    var s = this._super(record, suffix);
    return s + ".json";
  },

  serializer: DS.RESTSerializer.extend({
      extract: function(loader, json, type, record) {
          var root = this.rootForType(type);
          // now root is the string of the type
          // so, we have to create a new json hash with the root type and the actual data ( that dont have key type )
          newJSON = {} ;
          newJSON[root] = json ;
          json = newJSON  ;
          //

          this.sideload(loader, type, json, root);
          this.extractMeta(loader, type, json);

          if (json[root]) {
              if (record) { loader.updateId(record, json[root]); }
              this.extractRecordRepresentation(loader, type, json[root]);
          } else {
              Ember.Logger.warn("Extract requested, but no data given for " + type + ". This may cause weird problems.");
          }
      }
   }),

    ajax: function(url, type, hash) {
//        hash = hash || {};
//        hash.headers = hash.headers || {};
//        hash.headers['auth_code'] = App.Store.authToken;
        var promise = this._super(url, type, hash);
        return promise.then(function(json) {
            console.debug(json);
            delete json.pagination;         // remove pagination node from all Json
            return json;
        });
    }

});

App.Adapter.configure('App.Movie', {
   sideloadAs: 'pagination'     // se supone que deberia de coger el node pagination como un modelo aparte cuando recibe el json de movies pero no lo hace
});

App.Adapter.map( 'App.Movie', {
    artwork: { embedded: 'always' }
});
App.Adapter.map( 'App.Season', {
    artwork: { embedded: 'always' }
});
4

1 回答 1

0

In router.js I think that you need to use resource instead of route for any URL fragments that you want to result in API calls. routes are just for 'static' data.

于 2013-09-05T06:34:27.473 回答