Ember Cli模型人口

时间:2015-09-10 12:01:36

标签: javascript ember-data ember-cli

我正在Ember Cli上构建一个应用程序,这是我的第一个Ember应用程序。我已经在GIT上提交了应用程序: https://github.com/freshdev1/ember-test-project

问题是在adapters / payment-type.js中引用的服务正在给出有效的响应。响应将映射到模型上,但响应包含大约22个对象,其中只有最后一个对象被复制到模型,因为它显示在Chrome的Ember Inspector选项卡中。

其次,我无法在模型中显示任何属性值。

型号:

// app/models/payment-type.js

import DS from 'ember-data';

var attr = DS.attr;

var paymentTypes = DS.Model.extend({
    name : attr('string'),
    inoutFlag: attr('string'),
    shortCode: attr('string'),
    paymentType: attr('string'),
    bankAccountRequiredFlag: attr('string'),
    depositSlipFlag: attr('string'),
    maccPaymentFlag: attr('string'),
    referenceRequiredFlag: attr('string'),
    confirmationRequiredFlag: attr('string'),
    creditCardRequiredFlag: attr('string'),
    payeeRequiredFlag: attr('string'),
    affectsBankAccountFlag: attr('string'),
    clearanceRequiredFlag: attr('string'),
    paymentRequiredFlag: attr('string'),
    outstandingFlag: attr('string'),
    includeInBankFile: attr('string'),
    defaultDirectPayTypeCode: attr('string'),
    inspecieTransferFlag: attr('string')
});


export default paymentTypes;

路线:

// app/routes/paymentlisttype.js

import Ember from 'ember';

export default Ember.Route.extend({
    model: function(){
        return this.store.findAll('paymentType');
    }
});

模板(摘录):

// app/templates/paymenttypelist.js

{{#each payment-type as payType}}
<snip>
<td>{{payType.paymentType}}</td>
<td>{{payType.name}}</td>
<td>{{payType.shortCode}}</td>
<td>{{payType.depositSlipFlag}}</td>
td class="text-center"> {{input disabled="true" type="checkbox" value=payType.includeInBankFile }}</td>
<snip>

我做了什么?

- 从模型和其他文件夹中删除了所有不明确的文件。(您可能会在GIT上找到它们,但在本地它们不存在。)

我遵循的教程如下: https://www.youtube.com/watch?v=vLXGKNA4P_g

从服务器收到的JSON如下:

{
    "paymentTypes": [
        {
            "id": 0,
            "paymentType": "A",
            "depositSlipFlag": "X",
            "shortCode": "DISH",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "Y",
            "name": "Dishonour",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "N",
            "inoutFlag": "O",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "B",
            "depositSlipFlag": "N",
            "shortCode": "BD",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "Y",
            "name": "Bank Draft",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "Y",
            "payeeRequiredFlag": "Y",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "O",
            "clearanceRequiredFlag": "N",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "C",
            "depositSlipFlag": "X",
            "shortCode": "ADO       ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "CEMTEX",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "D",
            "depositSlipFlag": "X",
            "shortCode": "DDO       ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "Y",
            "name": "Direct Deposit Out",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "O",
            "clearanceRequiredFlag": "N",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "Y",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "E",
            "depositSlipFlag": "X",
            "shortCode": "DD        ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "Y",
            "name": "Bank Direct Deposit",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "O",
            "clearanceRequiredFlag": null,
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "F",
            "depositSlipFlag": "X",
            "shortCode": "DDR       ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "Y",
            "name": "Direct Debit Request",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "Y",
            "affectsBankAccountFlag": "N",
            "inoutFlag": "B",
            "clearanceRequiredFlag": "N",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "Y",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "I",
            "depositSlipFlag": "N",
            "shortCode": "INTRAN    ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "In  Internal Transfer",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "N",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "B",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "Y"
        },
        {
            "id": 0,
            "paymentType": "K",
            "depositSlipFlag": "X",
            "shortCode": "ANZBANK   ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "Y",
            "name": "ANZ Bank File",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "O",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "Y"
        },
        {
            "id": 0,
            "paymentType": "M",
            "depositSlipFlag": "X",
            "shortCode": "M/ORD     ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "Money Order (Australia Post)",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "Y"
        },
        {
            "id": 0,
            "paymentType": "N",
            "depositSlipFlag": "X",
            "shortCode": "INTERNAL  ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "N",
            "name": "Internal Transfer",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "B",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "O",
            "depositSlipFlag": "X",
            "shortCode": "OUTTRAN   ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "N",
            "name": "Out Internal Transfer",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "P",
            "depositSlipFlag": "X",
            "shortCode": "GRPC      ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "Split Payment Type",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "N",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "Q",
            "depositSlipFlag": "Q",
            "shortCode": "CHQ       ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "N",
            "name": "Cheque",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "Y",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "B",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "R",
            "depositSlipFlag": "X",
            "shortCode": "CHQR      ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "Y",
            "name": "Cheque Receipt",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "N",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "S",
            "depositSlipFlag": "X",
            "shortCode": "CASH      ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "Cash - Dollars and Coins",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "N",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "V",
            "depositSlipFlag": "X",
            "shortCode": "REV       ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "Reversal Deposit",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "N",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "W",
            "depositSlipFlag": "X",
            "shortCode": "BPAY      ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "BPay Payment",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "X",
            "depositSlipFlag": "X",
            "shortCode": "CORR      ",
            "maccPaymentFlag": "Y",
            "bankAccountRequiredFlag": "Y",
            "name": "New Corro Payment Type",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "B",
            "clearanceRequiredFlag": null,
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": "Q",
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "Y",
            "depositSlipFlag": "X",
            "shortCode": "CASH      ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "N",
            "name": "Cash - Dollars and Coins",
            "confirmationRequiredFlag": "Y",
            "referenceRequiredFlag": "N",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "N",
            "affectsBankAccountFlag": "Y",
            "inoutFlag": "I",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "N",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "Z",
            "depositSlipFlag": "X",
            "shortCode": "DDR_PAY   ",
            "maccPaymentFlag": "N",
            "bankAccountRequiredFlag": "Y",
            "name": "New DDR Payment",
            "confirmationRequiredFlag": "N",
            "referenceRequiredFlag": "Y",
            "creditCardRequiredFlag": "N",
            "payeeRequiredFlag": "Y",
            "affectsBankAccountFlag": "N",
            "inoutFlag": "I",
            "clearanceRequiredFlag": null,
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": "Y",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "j",
            "depositSlipFlag": "Q",
            "shortCode": "dfgdfgg   ",
            "maccPaymentFlag": null,
            "bankAccountRequiredFlag": null,
            "name": "gdfgg",
            "confirmationRequiredFlag": null,
            "referenceRequiredFlag": null,
            "creditCardRequiredFlag": null,
            "payeeRequiredFlag": null,
            "affectsBankAccountFlag": null,
            "inoutFlag": "O",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": null,
            "outstandingFlag": "N",
            "includeInBankFile": "Y",
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "N"
        },
        {
            "id": 0,
            "paymentType": "t",
            "depositSlipFlag": "N",
            "shortCode": "ertert    ",
            "maccPaymentFlag": null,
            "bankAccountRequiredFlag": null,
            "name": "erter",
            "confirmationRequiredFlag": null,
            "referenceRequiredFlag": null,
            "creditCardRequiredFlag": null,
            "payeeRequiredFlag": null,
            "affectsBankAccountFlag": null,
            "inoutFlag": "B",
            "clearanceRequiredFlag": "Y",
            "paymentRequiredFlag": "Y",
            "outstandingFlag": "N",
            "includeInBankFile": null,
            "defaultDirectPayTypeCode": null,
            "inspecieTransferFlag": "Y"
        }
    ]
}

请访问上面的网址,以帮助查看所有代码。

1 个答案:

答案 0 :(得分:0)

乍一看,我看到了一件事:JSON有效负载为所有模型返回了"id": 0的对象。

首先,我不认为"id": 0有效,你必须从1开始。
其次,如果你收到多个具有相同id的对象,则前面的对象会被以下内容覆盖,所以最后只剩下最新的。