import { _decorator, Component, instantiate, Label, Node, Prefab } from 'cc';
import { question_item } from './question_item';
const { ccclass, property } = _decorator;

@ccclass('question')
export class question extends Component {
    @property(Node) lab_question:Node;
    @property(Prefab) question_item_prefab:Prefab;
    @property(Node) content:Node;
    public initView(str_problem:string,memory_answer:string[],correct_answer:string,call_back){
        this.content.removeAllChildren()
        let answer_index = parseInt(correct_answer)-1;
        this.lab_question.getComponent(Label).string = str_problem;
        for (let index = 0; index < memory_answer.length; index++) {
            const answer = memory_answer[index];
            let item = instantiate(this.question_item_prefab)
            item.parent = this.content;
            item.getComponent(question_item).initView(answer,index===answer_index,call_back)
        }
    }
}


