我正在尝试从对Backgrid模板的laravel json响应中获取json值
我的laravel json响应是
return Response::json(
array(
'items'=> $articles->toArray()
));
它响应json数组,就像这些
{"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"}}]}
我的后网格单元格是
var CateoryType = Backgrid.Cell.extend({
template: _.template('<%=category.name%>'),
render: function () {
this.$el.html(this.template( this.model.toJSON() ));
this.delegateEvents();
return this;
}});
但我无法从json响应中获取类别的名称。如何从我的Backgrid Cell或任何其他访问方式获取类别名称?
问题是您没有从laravel返回准确的集合,您可以使用主干或laravel(最优)
相反,返回时只说
echo json_encode($articles->toArray());
使用主干解析方法:
在您的收藏中使用
parse : function(response){
return response.items
}