samedi 15 juillet 2017

TypeError: Cannot read property 'pushObject' of undefined

-Before I give any snippets of code, I want to explain the task that I have to implement.

-First of all, every class has many subjects and every class has many students. Every subject and student belongs to one class. Also, every subject and student has many grades. But one grade belongs to one subject and one student.

-I wanted first in controller to check if there is one grade with those parameters (student and subject), and then if there is that grade, just update marks property (type of 'array' which I have in app/transforms). So here is controller app/controllers/overviewofstudents.js:

import Ember from 'ember';

export default Ember.Controller.extend({
        showS: false,
        mark: "",

        actions:{
                showSubjects(){
                        this.toggleProperty('showS');
                },

                insertMark(val, val2){
                        var subject2 = this.get('store').peekRecord('subject', val2);
                        var student = this.get('store').peekRecord('student', val);
                        var mark2 = this.get('mark');

                        this.get('store').query('grade', {
                                filter: {
                                        student: student,
                                        subject: predmet2
                                }
                        }).then(function(mark){
                                if(mark == null){
                                        this.get('store').createRecord('grade', {
                                                mark: [mark2],
                                                student: student,
                                                subject: subject2
                                        }).save().then(function(grade){
                                                student.get('marks').pushObject(mark2);
                                                student.save();
                                                subject2.get('grades').pushObject(mark2);
                                                subject2.save();
                                        });
                                }else{
                                        mark.get('marks').pushObject(mark2);
                                        mark.save();
                                }
                        });
                }
        }
});

-And here is app/templates/overviewofstudents.hbs:

<br> <br> <br> <br> <br>
<center>

<table>

<h2> Chosen class:  </h2>

<br>

<i> Current students in class: </i> <br>

<ol> 

        <li>    </li>
        <button class="choose" > Show subjects </button>
        
                <br> Current subjects in class: 
                
                        <br> <b>  </b>
                         Izaberite ocenu: 
                        <select onchange=>
                                <option value="1"> 1 </option>
                                <option value="2"> 2 </option>
                                <option value="3"> 3 </option>
                                <option value="4"> 4 </option>
                                <option value="5"> 5 </option>
                        </select>
                        <br>
                        <button > Insert mark for student </button>
                                
        

        <b> Currently there are no students for the class! </b>

</ol>

</table>

</center>



Aucun commentaire:

Enregistrer un commentaire