sstephenson / eco

Embedded CoffeeScript templates
MIT License
1.71k stars 70 forks source link

Nested model? #53

Open netwire88 opened 12 years ago

netwire88 commented 12 years ago

Hi, I'm a eco newbie and I'm trying to integrate it with Backbone. I checked out Ryan Bates' RailsCast example. However, I'm having trouble accessing a simple get.

I can do this: <%= @stream.get('stream_type') %> which returns "project" But how do I get user.name? I tried <%= @stream.user.get('name') %> but I got error: Uncaught TypeError: Cannot call method 'get' of undefined

[ : { : : "id":"5004095283de4ca9ff000005", : : "stream_type":"project", : : "user": : : { : : : "id":"5002f30560de7d0ffb000003", : : : "name":"Regular User2" : : },

jonathangordon commented 11 years ago

If user is a Backbone model, then you should use @stream.get('user').get('name'). You need to use get() to access the user attribute, and user is a Backbone model.

mbhnyc commented 11 years ago

The best way to debug issues like this is to insert either a breakpoint in your compiled template in chrome/firebug, or a debugger statement in the code, which chrome/firebug will detect and pause output. Then you can just check "this" in the debugger and fiddle until you find the right reference.