1

I use can.Component to dispay JSON on the page.

can.Component.extend({
    tag: "some-app",
    scope: {
        items: new Items.List({}),
        displayedItems: function () {
            ...
            return items;
        }

    },
    helpers: {
     ...
    },
    events: {
        "{Items} created": function (Items, ev, newItem) {
            ...
        }
    }
})

How can I get "meta" section of received JSON (below) to the scope or helpers?

{
  "data": [
    {
      "description": "Some text",
      "id": 1,
      "measurement": "pcs",
      "name": "Name of item",
      "resource_uri": "/api/v1/item/1/"
    },
   {....}, {....}
    }
  ],
  "meta": {
    "limit": 20,
    "next": null,
    "offset": 0,
    "previous": null,
    "total_count": 3
  }
}

I can get it in console with Items.findAll().then(function(info){console.log(info.attr('meta'))}) , but I'm noob in (can.)js and can't understand how to get it in the place I need.

Alfredo Delgado
  • 689
  • 4
  • 12
Ilya
  • 99
  • 2
  • 12

1 Answers1

0

Instead of this:

scope: {
        items: new Items.List({})
}

make the request:

scope: {
        items: Items.findAll()
}

There are other ways to do this as well, in the template(not advised), or creating the request in another controller or component and passing in to the instantiation of the component.

If you want more specifics, you would nee to update your question with more details on your model.