0

我正在尝试通过 Firebase 支持的 ember 应用程序显示一些 CI 信息。如果我这样做,this.store.find('plan');它会获取并显示所需项目的计划,但它不会像我想要的那样自动异步获取计划。我不太确定我做错了什么。

DEBUG: -------------------------------
DEBUG: Ember      : 1.9.0-beta.1+canary.8105a1bb 
DEBUG: Ember Data : 1.0.0-beta.11+canary.d96c747da5
DEBUG: EmberFire  : 1.2.7
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 1.10.2
DEBUG: ------------------------------- 


App = Ember.Application.create();

App.Router.map(function() {
  // put your routes here
});

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('project');
  }
});

App.ApplicationAdapter = DS.FirebaseAdapter.extend({
  firebase: new Firebase('https://my.firebaseio.com/api-data/')
});

App.Project = DS.Model.extend({
  name: DS.attr('string'),
  plans: DS.hasMany('plan', { async: true })
});

App.Plan = DS.Model.extend({
  project: DS.belongsTo('project', { async: true }),
  shortName: DS.attr('string'),
  shortKey: DS.attr('string'),
  type: DS.attr('string'),
  enabled: DS.attr('boolean'),
  name: DS.attr('string'),
  description: DS.attr('string'),
  isBuilding: DS.attr('boolean'),
  averageBuildTimeInSeconds: DS.attr('number')
});

我的模板

  <script type="text/x-handlebars" data-template-name="index">
    <ul>
    {{#each project in model}}
      <li>
        <h3>{{project.name}}</h3>
        <ul>
          {{#each plan in project.plans}}
            <li>{{plan.name}}</li>
          {{else}}
            <li>no plans</li>
          {{/each}}
         </ul>
      </li>
    {{/each}}
    </ul>
  </script>

当我尝试访问 project.plans 属性时,如何让 ember-data 异步关系自动获取?

编辑:

我尝试使用 Ember-CLI 的 http-mock 进行模拟,并将以下内容发回/projects

{"plans":[{id: '10', project: '1', name: 'test', plans: ['10']}]}

现在正在添加计划数组。我现在只需要弄清楚这在firebase上是如何工作的。

4

1 回答 1

0

在我的初始种子数据之后使用 Firebase 时,我获取了每种模型类型并在所有实例上调用 save。这导致 Firebase 为异步数据数组正确填充。这坚持如下:

/projects

{
    "AS": {
        "name": "AS",
        "plans": {
            "AS-AS": true
        }
    },
    "F": {
        "name": "F",
        "plans": {
            "F-INT": true,
            "F-QA": true,
            "F-STAG": true
        }
    }
}

/plans

{
    "AS-AS": {
        "averageBuildTimeInSeconds": 23,
        "description": "",
        "enabled": true,
        "isBuilding": false,
        "name": "AS - AS",
        "project": "AS",
        "shortKey": "AS",
        "shortName": "AS",
        "type": "chain"
    },
    "F-INT": {
        "averageBuildTimeInSeconds": 18,
        "description": "Integration build",
        "enabled": true,
        "isBuilding": false,
        "name": "F - Integration",
        "project": "F",
        "shortKey": "INT",
        "shortName": "Integration",
        "type": "chain"
    },
    "F-QA": {
        "averageBuildTimeInSeconds": 38,
        "description": "Release from Stage to QA",
        "enabled": true,
        "isBuilding": false,
        "name": "F - QA",
        "project": "F",
        "shortKey": "QA",
        "shortName": "QA",
        "type": "chain"
    },
    "F-STAG": {
        "averageBuildTimeInSeconds": 16,
        "description": "Stage Build and Deploy",
        "enabled": true,
        "isBuilding": false,
        "name": "F - Stage",
        "project": "F",
        "shortKey": "STAG",
        "shortName": "Stage",
        "type": "chain"
    }
}
于 2014-10-12T22:29:40.937 回答