javascript - cannot populate backbone collection from backbone.js tutorial -


I'm working my way through the backbone tutorial:

I'm working on the DEGENGO + TTPP I'm using the tutorial for tips and foreground tutorials in the form of backdoors + underscores.

However, I am unable to loop through the collection of users which I get.

Here my code is a DJ ango template):

  {% "my_app / base_template.html"%} {% block script%} extends  gt; & lt; tr & gt; & lt; td & gt; & lt;% = user.get ('username)'% & gt; ; & Lt; / td> & lt; / tr & gt; & lt;%}); & Gt%; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Script & gt; & Lt; Script type = "application / javascript" & gt; $ (Document) .ready (function () {var Users = Backbone.Collection.extend ({url: "/ api / q / user /"}) user list = backbone.view extension ({el: ".user_list ", Render: function () {var key = it; var user = new user (); users.fetch ({success: function (user) {var template = _.template ($ (" # users_template "). Html ( ); {# I think the problem is almost here}. $ El.html (template ({user: users.models}))}}});}}); var user_list = new UserList (); Var Router = backbone.routor.andend ({path: {"": "index"}}) var router = new router (); route Kon ( "Route index", function () {user_list.render ();}); backbone. History.start ();}); & Lt; / Script & gt; {% Endblock%} {# / scripts #} {% block content%} & lt; Div class = "my_stuff" & gt; & Lt; Div class = "user_list" /> & Lt; / Div & gt; {% Endblock%} {/ code>  

and I can confirm that "my_domain / api / q / user /" gives the right content (2 users: admin and other user "Bob" Zero, "Offset": 0, "Previous": blank, "total_count": 2}, " Objects ": [{" date_joined ":" 2014-11-04T04: 28: 17 "," email ":" bob@bob.com "," first_name ":" bob "," id ": 2," is_active " True, "is_staff": wrong, "is_superuser": wrong, "last_ login": "2014-11-04T05: 13: 46.908539", "last_name": "bobington", "password": "something hash", " Resource_ory ":" / API / Q / Usage "Admin@domain.com", "first_name": "user_name": "user name": "bob"}, {"date_joint": "2014-11-03T13: 44: 04.356967", "email" True, "is_supalf": True, "is_superuser": True, "last_login": "2014-11-04T06: 06: 51.336317", "last_name": "true" "," Password ":" some_hash "," resource_uri ":" / Api / q / user / 1 / "," user name ":" administrator "}]}

What am I doing wrong? Am I passing through templates other than {{users.models}}? Am I doing piping incorrectly through that structure?

Thank you.

Box, backbone expects that your object will be in the root of your reaction. If they are not, then some help is needed to determine how it can be used when using model objects.

Actually you only need to define a backbone model and add your own parsing function:

  var user = Backbone.Model.extend ({parse: Function (feedback) {return response.objects;}});  

Your model will now know where to set that property.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -