Ember-在视图中显示模型数据

时间:2014-01-27 09:18:54

标签: javascript view ember.js model

我想知道如何在ember视图中显示模型数据,例如组织模型>名称字段 我试过这样的事情。

组织视图

OrganizationObserver : function(){
    var organizationModel = this.get('controller.organizations');
    //this.OrganizationComputedProperty(organizationModel);
    console.log(organizationModel);
}.observes('controller.organizations').on('init'),

OrganizationComputedProperty: function(){
  console.log("herrro");
}.property('organization'),

模型

var Organization = DS.Model.extend({
    name: DS.attr('string'),
    address: DS.belongsTo('agents/address')
});

// Initial data for Organization model, only applies when using
// FixtureAdapter
Organization.FIXTURES = [
 {
   id: 1,
   name: 'TU',
   address: 1,
 },
  {
   id: 2,
   name: 'TLU',
   address: 2,
 }
 ];

主要的hbs

{{#each personFormCount}}
{{view 'organization'}}
{{/each}}

控制器

personFormCount: [{id: 1}, {id: 2}]

但我知道这是错的,因为他们会注意不会在模特中发生的变化行为。

干杯,

克里斯蒂安

1 个答案:

答案 0 :(得分:0)

因为我能够通过this.get('controller.organizations')将模型添加到我的视图中 这是在路线中定义的

controller.set('organizations', this.store.findAll('agents/organization'));

我再次看了一下选择

{{view Ember.Select
contentBinding="organizations"
optionValuePath="content.id"
optionLabelPath="content.name"
selectionBinding="selectedAgent"
class="form-control"
}}

我刚刚将controller.organizations添加到contentBinding

{{view Ember.Select
contentBinding="controller.organizations"
optionValuePath="content.id"
optionLabelPath="content.name"
selectionBinding="view.selectedAgent"
class="form-control"
}}