小编Rom*_*tro的帖子

model在控制器上返回null

我正在使用路由器和控制器,我需要在控制器上完成一些操作,这是我的模型代码

AcornsTest.StockRoute = Ember.Route.extend({
  model: function(params) {
    "use strict";
    var url_params = params.slug.split('|'),
      url = AcornsTest.Config.quandl.URL + '/' + url_params[0] + '/' + url_params[1] + '.json',
      stockInStore = this.store.getById('stock', url_params[1]),
      today =  new Date(),
      yearAgo = new Date(),
      self = this;

    yearAgo.setFullYear(today.getFullYear() - 1);
    today = today.getFullYear()+'-'+today.getMonth()+'-'+today.getDate();
    yearAgo = yearAgo.getFullYear()+'-'+yearAgo.getMonth()+'-'+yearAgo.getDate();

    if(stockInStore && stockInStore.get('data').length) {
      return stockInStore;
    }

    return Ember.$.getJSON(url,{ trim_start: yearAgo, trim_end: today, auth_token: AcornsTest.Config.quandl.APIKEY })
      .then(function(data) {
        if(stockInStore) {
           return stockInStore.set('data', data.data);
        } else {
           return self.store.createRecord('stock', {
            id: …
Run Code Online (Sandbox Code Playgroud)

ember.js ember-data

5
推荐指数
1
解决办法
1779
查看次数

标签 统计

ember-data ×1

ember.js ×1