0

I am trying to get json value from laravel json response to Backgrid template

My laravel json response is

 return Response::json(
    array(
        'items'=> $articles->toArray()
    ));

It response json array like these

{"items":[{"id":30,"title":"Tester","body":"tesrter","user_id":566,"user_nickname_id":0,"category_id":1,"community_id":0,"ref_link":"face.com","status":3,"points":0,"editor_id":566,"created_at":"2015-03-21 15:53:43","updated_at":"2015-03-21 09:23:43","category":{"id":1,"name":"Cupcake wrappers","description":"","created_to":"2015-02-27 13:53:15","updated_to":"0000-00-00 00:00:00"}}]}

My backgrid cell is

var CateoryType = Backgrid.Cell.extend({
  template: _.template('<%=category.name%>'),
  render: function () {
    this.$el.html(this.template( this.model.toJSON() ));
    this.delegateEvents();
    return this;
  }});

But I couldn't get category 's name from json response. How Could I get Category name from my Backgrid Cell or any other way to access it?

Nay
  • 1,223
  • 2
  • 9
  • 18

1 Answers1

0

the problem being you are not returning an exact collection from your laravel, you can do it in either using backbone or laravel(optimal)

instead return just say

echo json_encode($articles->toArray());

Using backbone parse method:

in your collection use

parse : function(response){
   return response.items
}
StateLess
  • 5,344
  • 3
  • 20
  • 29