0

Please see: http://jsbin.com/UZETowi/3/edit

This code runs fine locally on my computer, but doesn't run in JSBin for some reason. What's wrong?

Here's my problem: accessing items.length from the handlebars template produced the correct answer, but when I tried to output same value via console.log, I get "undefined." Why is this?

ptmoy2
  • 311
  • 1
  • 4
  • 13

1 Answers1

1

add the length inside of the getter, items is a collection, not an array, so it doesn't have the length property defined on the object itself.

 console.log (this.get('items.length'));

http://jsbin.com/obEmOfuB/2/edit

Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • Thank you; it worked. Do you know why the code I posted in jsbin fails to run? When I post code relating to questions, I always get the code to run locally first, then copy over to jsbin or jfiddle. But at least half the time, I struggle to get code to run on those 2 platforms. – ptmoy2 Nov 19 '13 at 15:33
  • You need to point your js files to either a CDN or somewhere that doesn't deliver the file as TEXT/HTML. http://cdnjs.com/ is really good, additionally you can start off with a templated version of ember at emberjs.jsbin.com – Kingpin2k Nov 19 '13 at 15:52
  • @ptmoy2 Your JQuery is too modern Error: assertion failed: Ember Views require jQuery 1.7 (>= 1.7.2) or 1.8 http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js Line 52 and what kingpin2k had said also – Edu Nov 19 '13 at 15:52
  • To Edu: but I used the latest version of jquery locally without getting this error. – ptmoy2 Nov 19 '13 at 16:14
  • It has nothing to do with jquery, it's because jsbin doesn't like when you access js files that are delivered as text/html. It throws the error in the console. http://jsbin.com/obEmOfuB/2/edit – Kingpin2k Nov 19 '13 at 16:18