7.10 Models--handling Metadata (processing metadata)

Source: Internet
Author: User

1. With the records returned from the store, you may need to work with some meta data. Metadata is a data that accompanies a particular model or Tyep , not a record.

2. Paging is a common example of using metadata. Imagine a blog that has more posts than you can show at one time. You might find this:

this. Store.query ("Post", {  ten,  0});

3. To get the data from different pages, you can simply change the offset to 10. So far, everything is fine. But if you know how many pages of data you have? Your server needs to return the total number of records as part of the metadata.

4. Each serialization will expect to return different meta data. For example, the JSON deserializer for Ember data looks for a meta key:

{  "post": {    "id": 1,    "title": "Progressive enhancement is Dead",    "Comments": ["1", "2"],    "links": {      "user": "/people/tomdale"    },    // ...   },  " Meta ": {    " total ": +}  }

5. Regardless of the serializer used, this metadata is extracted from the response. You can read it by using . Get (' meta ') .

6. This can be done in the result of calling Store.query () :

Store.query (' Post '). Then (Result) = {  = result.get (' meta ');})

7. In the belongsto relationship:

Let post = Store.peekrecord (' Post ', 1);p ost.get (' author '). Then ((author) = {  = Author.get (' (Meta ');});

Or in a hasmany relationship:

Let post = Store.peekrecord (' Post ', 1);p ost.get (' comments '). Then ((comments) = {  = Comments.get (' meta ');});

8. After reading it,meta.total can be used to calculate how many pages there are.

7.10 Models--handling Metadata (processing metadata)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.