0
votes

Hello I am trying to create in Backbone Marionette something similar to the "Rest Backbone Example, Exercise 2" from Addy Osmani's Backbone Fundamentals.

See here: http://github.com/addyosmani/backbone-fundamentals/tree/gh-pages/exercise-2

I understand most of it, but am having difficulty parsing/fetching the json to a backbone marionette compositeview.

A simple example of the rendering im trying to do is like this: http:/jsfiddle.net/w3r5B/ (Inspired by David Sulc's tutorial, http://davidsulc.github.com/backbone.marionette-collection-example/)

*The JSfiddle example is JSON to Marionette, but im trying to sent the data straight from the server.

Im using node, express, mongoose, mongodb btw. Thanks.

1
What is it exactly that's not working with your JSON when you fetch it directly from the server?Thalis K.
Thanks for replying. I believe my problem is on the Backbone/marionette side and showing JSON to the client in a Marionette collection. I have read some posts on here and believe it may have to do with using fetch or parse with the backbone collection, but have not been successful in doing so. I'm able to get JSON from my server, for example if I go to, localhost:3000/api/cats I would get the following: [{ "catname": "Mike", "_id": "5152e383502ee66c27000003", "__v": 0 }, { "catname": "Bobby", "_id": "5152e388502ee66c27000004", "__v": 0 } ]1ManStartup
I see in your jsfiddle example that you are using in the template <%= name %> instead of the correct catname returned in your JSON. Still not clear what exactly the problem is though. It would help stating what you expect to get and what you actually get in the final rendered page.Thalis K.
The jsfiddle is not connected to the JSON REST server since im running it local. Yes I will change <%= name %> with <%= catname %> (I have catname on my local version). Im basically trying to render it as an ordered list like this: //Append li's after ul // <li> each <%= catname %> here </li> <br> <ul> <li> Mike </li> <li> Bobby</li> </ul>1ManStartup
Yes, I realized the jsfiddle is not related to the REST server; I just commented on the template issue in case you had it wrong in the REST scenario as well. So let me ask again: what is it exactly NOT working in the REST case? The jsfiddle example is just fine. The difference between the jsfiddle and your local REST case is in the tags. The AngryCatView's tagName should be 'li' and the AngryCatsView's should be 'ul'. Additionally you don't need to override appendHTML() any more since you are just appending the <li>'s, which is the default behavior.Thalis K.

1 Answers

0
votes

I figured it out. I just had to fetch the collection outside of the backbone collection. Thanks.