1

各操作の収益名をページに表示したい。belongs_to を使用する必要があると思いますが、方法がわかりません。

私は2つのテーブルを持っています:

収入操作: (id, sum, Income_id) 収入: (id, name)

models/income.js.coffee

EmberMoney.Income = DS.Model.extend
  name: DS.attr('string')
  description: DS.attr('string')

models/income_operation.js.coffee

EmberMoney.IncomeOperation = DS.Model.extend
  sum: DS.attr('number')
  incomeId: DS.belongsTo('EmberMoney.Income')  // I think i should be so

ルート/addincome_route.js.coffee

EmberMoney.AddincomeRoute = Ember.Route.extend
  model: ->
    EmberMoney.IncomeOperation.createRecord()
  setupController: (controller, model) ->
    controller.set('incomes', EmberMoney.Income.find())
    controller.set('operations', EmberMoney.IncomeOperation.find())
    controller.set('content', model)

テンプレート/addincome.handlebars

    {{#each operation in controller.operations}}
      <div>
        // **Here i want to show income name instead of ID**
        {{operation.incomeId}}
        {{operation.storageId}}
        {{operation.sum}}
        {{operation.date}}
      </div>
    {{/each}}
4

1 に答える 1

1

incomeId: DS.belongsTo('EmberMoney.Income')に変更する必要があると思いますincome: DS.belongsTo('EmberMoney.Income')

その後、{{operation.income.name}}あなたに収入の名前を与える必要があります。

于 2013-03-28T10:30:42.497 に答える