Total number of records retrieved by the ObjectStore onfetch Method

Source: Internet
Author: User

From: http://blog.csdn.net/earthhour/article/details/38686029

 

Total number of records retrieved by the ObjectStore onfetch Method

Require (['dojo/when']); var JSON = new jsonrest ({target: URL}); store = new ObjectStore ({ObjectStore: JSON}); store. onfetch = function (results) {// Method 1: results. then (function (RS) {console. log ('rs len-> ', Rs. length) ;}); // Method 2: When (results, function (results) {console. log ('when-> ', results. length); console. dir (results );});};

Small Example of dojo (14) preprocessing of the data presented to the grid

 

Sometimes the data we obtain from the background may not meet the needs of page display. For example, if a field value in the background data is "1/0", we want to display it as "yes/no ". This requires data conversion, that is, preprocessing.

There can be two methods. Assume that the use scenario is jsonrest + ObjectStore combination, which provides the grid with the ability to load data lazily.

Method 1: pre-process the data in the store.

 

[JavaScript]View plaincopy
  1. VaR JSON = new jsonrest ({
  2. Target: URL
  3. });
  4. VaR store = new ObjectStore ({ObjectStore: JSON });
  5. Store. onfetch = function (results ){
  6. Results. foreach (function (item ){
  7. // Pre-process data here
  8. If (item. Admin = '1 '){
  9. Item. Admin = 'yes ';
  10. } Else {
  11. Item. Admin = 'no ';
  12. }
  13. });
  14. };

Method 2: preprocessing in grid structure.

 

[JavaScript]View plaincopy
  1. VaR layout = [
  2. [{
  3. 'Name': 'column 1 ',
  4. 'Field': 'id ',
  5. 'Width': '100px'
  6. },{
  7. 'Name': 'column 2 ',
  8. 'Field': 'admin ',
  9. 'Width': '100px ',
  10. Get: function (colindex, item ){
  11. // Processing data
  12. If (item. Admin = '1 '){
  13. Return 'is ';
  14. } Else {
  15. Return 'no ';
  16. }
  17. }
  18. },{
  19. 'Name': 'column 3 ',
  20. 'Field': 'desc ',
  21. 'Width': '200px'
  22. }]
  23. ];

In addition, JSON data with internal objects, such:

 

{"Name": "Chen", "Age": "24", "phone": {"company": "123", "home": "456 ", "private": "789 "}}

We want to display the company attribute of the internal object to the grid. If we write 'field': 'phone. company 'certainly won't work, so it is also suitable to use one of the two methods mentioned above for conversion.

Assume that the second method is used:

 

[JavaScript]View plaincopy
  1. {
  2. 'Name': 'column 2 ',
  3. 'Field': 'phone. Company ',
  4. 'Width': '100px ',
  5. Get: function (colindex, item ){
  6. // Processing data
  7. Return item. Phone. Company;
  8. }
  9. }

Update:

When the second method is used, the grid refresh will not take effect because of the get method. The Code is as follows:

 

[JavaScript]View plaincopy
  1. Grid. Resize ();
  2. Grid. _ refresh ();

The reason is unclear. Therefore, if you need to use grid refresh, use the first method.

 


 

Total number of records retrieved by the ObjectStore onfetch Method

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.