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
- VaR JSON = new jsonrest ({
- Target: URL
- });
- VaR store = new ObjectStore ({ObjectStore: JSON });
- Store. onfetch = function (results ){
- Results. foreach (function (item ){
- // Pre-process data here
- If (item. Admin = '1 '){
- Item. Admin = 'yes ';
- } Else {
- Item. Admin = 'no ';
- }
- });
- };
Method 2: preprocessing in grid structure.
[JavaScript]View plaincopy
- VaR layout = [
- [{
- 'Name': 'column 1 ',
- 'Field': 'id ',
- 'Width': '100px'
- },{
- 'Name': 'column 2 ',
- 'Field': 'admin ',
- 'Width': '100px ',
- Get: function (colindex, item ){
- // Processing data
- If (item. Admin = '1 '){
- Return 'is ';
- } Else {
- Return 'no ';
- }
- }
- },{
- 'Name': 'column 3 ',
- 'Field': 'desc ',
- 'Width': '200px'
- }]
- ];
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
- {
- 'Name': 'column 2 ',
- 'Field': 'phone. Company ',
- 'Width': '100px ',
- Get: function (colindex, item ){
- // Processing data
- Return item. Phone. Company;
- }
- }
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
- Grid. Resize ();
- 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