dimanche 9 octobre 2016

Ember 2.8 : .get('property') is not a function error when using on an object

I have a function in my route's controller that tries to get the property of an object I know exists.

play.js (controller)

toggleIsFlipped(cardInstance) {
      //testing out .get()
      let a = cardInstance.get('isFlipped');
      console.log(a);
      this.toggleProperty('isFlipped');
    }

The offending line is the first line, where I get this error:

play.js:42 Uncaught TypeError: cardInstance.get is not a function

When I console.log cardInstance by itself, it correctly logs the object. I have checked and it does indeed have a key called 'isFlipped'. The cardInstance object comes a component called game-card. Here is the rest of the code

play.hbs -> instance is an object like so {isFlipped: false, url: 'someurl'}

<div class="col-sm-12">
  
    
  
</div>

game-card.hbs

<span >
  <div id="card"  class = "">
    <figure class="front"></figure>
    <figure class="back">
      <img src=  />
    </figure>
  </div>
</span>

game-card.js

import Ember from 'ember';

export default Ember.Component.extend({
  classNames: ['flip-container'],
  actions: {
    doCardClick(param){
      this.get('onCardClick')(param);
    },
    doCardFlip(param) {
      this.get('toggleIsFlipped')(param);
    }
  }
});

I am not sure if by passing the parameter to toggleIsFlipped() I am somehow manipulating the ember object and disallowing .get() functions to be called on it. Either way, I have no clue what is happening. Thanks for your help.




Aucun commentaire:

Enregistrer un commentaire