0

JSON に別の JSON が含まれています。質問のリスト内に回答のリストを表示する必要があります

現時点で見たいものの例:

質問 1+2=?

回答

-1

-5

-3 ....

JSON 回答から最初の回答のみを表示するようになりました

ここに画像の説明を入力

私のJSON

[
    {
        "id": 7,
        "answers": [
            {
                "id": 6,
                "answer": "1",
                "isCorrect": false
            },
            {
                "id": 7,
                "answer": "5",
                "isCorrect": false
            },
            {
                "id": 5,
                "answer": "3",
                "isCorrect": true
            }
        ],
        "question": "1+2=?"
    },
    {
        "id": 14,
        "answers": [
            {
                "id": 28,
                "answer": "5",
                "isCorrect": false
            },
            {
                "id": 31,
                "answer": "7",
                "isCorrect": true
            },
            {
                "id": 29,
                "answer": "2",
                "isCorrect": false
            },
            {
                "id": 30,
                "answer": "6",
                "isCorrect": false
            }
        ],
        "question": "2+5=?"
    },
    {
        "id": 9,
        "answers": [
            {
                "id": 13,
                "answer": "3",
                "isCorrect": false
            },
            {
                "id": 11,
                "answer": "5",
                "isCorrect": false
            },
            {
                "id": 14,
                "answer": "6",
                "isCorrect": true
            },
            {
                "id": 12,
                "answer": "7",
                "isCorrect": false
            }
        ],
        "question": "3+3=?"
    }
]

私のモデルとビュー

Ext.define('Sencha.model.Question', {
    extend: 'Ext.data.Model',

    requires: ['Sencha.model.Answer'],

    config: {
        fields: [
            'question'
        ],

        proxy: {
            type: 'ajax',
            url: 'contacts.json',
            reader : {
                type : 'json'
            }
        },


        hasMany: {
            model: "Sencha.model.Answer",
            associationKey: 'answers'
        }
    }
});

Ext.define('Sencha.model.Answer', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            'answer'
        ],

        belongsTo: "Sencha.model.Question"
    }
});

Ext.define('Sencha.view.Questions', {
    extend: 'Ext.List',
    xtype: 'questions',

    config: {
        title: 'Stores',
        cls: 'x-questions',

        store: 'Questions',
        itemTpl:[
            '{question}',
            '<div>',
                '<h2><b>Answers</b></h2>',
                '<tpl for="answers">',
                    '<div> - {answer}</div>',
                '</tpl>',
            '</div>'
        ].join('')
    }
});
Ext.define('Sencha.view.Answer', {
    extend: 'Ext.List',
    xtype: 'answer',

    config: {
        title: 'Answer',
        cls: 'x-questions',

        store: 'Questions',
        itemTpl: [
        '<div>{answer}</div>'
        ].join('')
    }
});

どうも!

4

1 に答える 1