【问题标题】:Ember- Showing models data in viewEmber - 在视图中显示模型数据
【发布时间】:2014-01-27 09:18:54
【问题描述】:

我想知道,如何在 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}]

但我知道那是错误的,因为他们会注意模型中不会发生的变化行为..

干杯,

克里斯蒂安

【问题讨论】:

  • 请发布模型定义和任何其他相关代码
  • @PanagiotisPanagi 完成

标签: javascript view ember.js model


【解决方案1】:

因为我能够通过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"
}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    相关资源
    最近更新 更多