1

我想在页面上显示每个操作的收入名称。我想我需要使用belongs_to,但我不知道如何。

我有两张桌子:

IncomeOperation: (id, sum, income_id) 收入: (id, name)

模型/income.js.coffee

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

模型/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 回答