路由器忽略资源的路径,始终发出相同的请求

时间:2013-09-03 07:20:36

标签: ember.js

我的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会忽略任何嵌套的网址。

对我做错了什么的想法?

更新

我必须自定义我的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' }
});

1 个答案:

答案 0 :(得分:0)

router.js中,我认为您需要使用resource代替route来处理您希望导致API调用的任何网址碎片。 routes仅用于“静态”数据。