dimanche 8 janvier 2017

Update an Array Element for a Property inside Service

export default Ember.Service.extend({
    currentQuizIndex: 0,
    quizzes: [
        {
            answer: '',
            inspected: true,
            rects: [],
            selected: false,
            src: '/assets/images/sample-image0.jpg'
        },
        {
            answer: '',
            inspected: true,
            rects: [],
            selected: false,
            src: '/assets/images/sample-image1.jpg'
        },
        {
            answer: '',
            inspected: false,
            rects: [],
            selected: false,
            src: '/assets/images/sample-image2.jpg'
        }
    ],

...

I would like to update the image selected state by providing an index, so I declare the following function,

highLightQuiz(index) {
    const target = this.get('quizzes').get('1');
    console.log(target);  // DO produce the desired target element
    target.set('selected', true);
},

However, it produce an Uncaught TypeError (see below)

quiz-list.js:78 Uncaught TypeError: target.set is not a function
    at Class.highLightQuiz (quiz-list.js:78)
    at Class.click (image-thumbnail.js:87)
    at Class.trigger (ember.debug.js:41454)
    at Class.superWrapper [as trigger] (ember.debug.js:39636)
    at Backburner.run (ember.debug.js:720)
    at Backburner.join (ember.debug.js:746)
    at Function.run.join (ember.debug.js:21556)
    at ember.debug.js:41584
    at Object.flaggedInstrument (ember.debug.js:17747)
    at Object.handleEvent (ember.debug.js:41583)

In the console, I can see there is a method called set selected: GETTER_FUNCTION(). Did I miss anything?

enter image description here




Aucun commentaire:

Enregistrer un commentaire