【问题标题】:How to access values in a multidimensional JSON array from backgrid template如何从 backgrid 模板访问多维 JSON 数组中的值
【发布时间】:2015-05-27 16:55:31
【问题描述】:

我正在尝试从 laravel json 对 Backgrid 模板的响应中获取 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 响应中获取 category 的名称。 如何从我的 Backgrid Cell 或任何其他方式获取类别名称?

【问题讨论】:

    标签: json backbone.js laravel-4 backgrid


    【解决方案1】:

    问题是您没有从 laravel 返回确切的集合,您可以使用骨干网或 laravel(最佳)来完成

    而不是直接说

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

    使用主干parse方法:

    在你的收藏中使用

    parse : function(response){
       return response.items
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2012-12-07
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多