last day (14 days later) » 

5:32 AM
0
A: Set property in forEach loop

Duncan WalkerIn JS (I tried to use a coffee convertor but it didn't look correct): formTypesWithUsed: function() { return this.get('formTypes').forEach(function(formType) { formType.set('formTypeUsed', true); }); }.property('formTypes.[]'), So long as you used {{#each formTypesWithUsed}} in your te...

 
Hey Duncan! I am such a noob. Sometimes with coffeescript I forget which 'this' I'm referring to. For some reason I'm still getting 'undefined is not a function' though.
 
Is formTypes definitely an Ember.Array?
 
It's literally declared just like it is above. I think my main problem is that I'm not using the formTypes array the correct 'Ember' way like you said. How do I declare that array in the right way so that Ember knows how to manipulate it?
 
Oh, sorry I didn't see that. Try formTypes: Em.A([ //... objects here ]).
 
Sorry I had a typo in the code. It's fixed now.
Now there is no error but nothing shows up in the list. If I change it back to the other, they show up but it throws the error.
Sorry I think it may be a coffescript thing. One minute.
Ok I think the array is good to go now but I still get the undefined type error when I try set anything on formType.
 
5:32 AM
If you make an emberjs.jsbin.com I probably have a better chance of figuring out what's going wrong here.
 
Will do. Thanks again.
 
So the basic problem is that you can't call set on each item in the array because they're not ember objects, just regular objects.
 
5:43 AM
Hey Duncan. I didn't even know there was a chat on here. You are teaching me so many new things. Here is the jsbin: emberjs.jsbin.com/tacolofe/1/edit
Sorry it took a bit to convert the coffescript over.
Hmmmm the object thing does sound like it would be the problem.
So basically I need to be creating an Ember array of Ember objects?
 
6:09 AM
I think I may have gotten it to work with this:
formTypes = @get('formTypes').map (form)->
Em.Object.create().setProperties(form)

formTypes.map (formType)->
formType.set 'formTypeUsed', true
I'll put it in the bin
 
 
9 hours later…
3:02 PM
I didn't know there was a chat either! Haha. In this case, the simplest way to do it would be as follows:
formTypesWithUsed: function() {
return this.get('formTypes').forEach(function(formType) {
formType.formTypeUsed = true;
});
}.property('formTypes.[]'),
Or:

formTypesWithUsed: function() {
return this.get('formTypes').forEach(function(formType) {
formType[formTypeUsed] = true;
});
}.property('formTypes.[]'),
Both of those ways are not using the Ember methods however
Thus, I don't think the observes would update
 

last day (14 days later) »