Changeset 363
- Timestamp:
- 07/17/12 11:52:08 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui/client/rft
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
r362 r363 46 46 })); 47 47 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1}) 48 .for Each(lang.hitch(this,function(value,key){48 .forPairs(lang.hitch(this,function(value,key){ 49 49 this._createCategoryTab(key[0],value); 50 50 })); … … 68 68 categoryMap._filled = true; 69 69 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]}) 70 .for Each(lang.hitch(this,function(value,key){70 .forPairs(lang.hitch(this,function(value,key){ 71 71 this._createTopicSelector(key[1],category,value); 72 72 })); … … 94 94 if (!topicMap._filled) { 95 95 store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]}) 96 .forEach(lang.hitch(this,function(value ,key){96 .forEach(lang.hitch(this,function(value){ 97 97 topicMap._widget.addItem(value); 98 98 })); -
Dev/branches/rest-dojo-ui/client/rft/store.js
r362 r363 2 2 function(declare,lang,array,Deferred,xhr,JSON,QueryResults){ 3 3 4 var CouchStore = declare( "rft.store",null, {4 var CouchStore = declare(null, { 5 5 /** dojo.Store implementation for CouchDB 6 6 * … … 43 43 }, 44 44 put: function(object, options){ 45 // summary: 46 // put an object in CouchDB 47 // object: Object 48 // The object to put 49 // options: Object 50 // Options object as 51 // id: String 52 // 45 53 options = options || {}; 46 54 … … 91 99 }, 92 100 query: function(query, options){ 101 // summary: 102 // query a couchdb view 103 // query: String 104 // name of a couchdb view you want to query, relative to the current database 105 // options: Object 106 // options object as 107 // start: Number 108 // Start results at this item 109 // count: Number 110 // Number of items to return 111 // sort: [{attribute:'key',descending:true|false}] 112 // CouchDB only support sorting by key, so only 'key' 113 // is allowed as attribute value. Multiple sort items 114 // are ignored. 115 // key: String|Array|Object 116 // Return only values with this key. 117 // Excludes start/endkey usage. 118 // startkey: String|Array|Object 119 // Return values starting from this key. 120 // endkey: String|Array|Object 121 // Return values with key lower than this key. 122 // include_docs: true|false 123 // Return the full documents instead of the view 124 // values. 125 // reduce: true|false 126 // Execute reduce on the view or not. Default depends 127 // on if a reduce function is defined on the view. 128 // group: true|false 129 // Should values be grouped per key or not? Default 130 // is false. 131 // group_level: Number 132 // When group = true and the key is an array, 133 // determines which elements starting from the first 134 // are used for grouping. Default is 0. 135 // get_keys: true|false 136 // Instead of returning the values or documents, 137 // return the array of keys as the result. 138 // This does not affect the forPairs function. 93 139 options = options || {}; 94 140 … … 161 207 dfd.reject(result.reason); 162 208 } else { 163 dfd.resolve( 164 array.map(result.rows, 165 function(result){ 166 return [result.key, options.include_docs === true ? result.doc : result.value]; 167 })); 209 var results; 210 var values = array.map(result.rows,function(result){ 211 return options.include_docs === true ? result.doc : result.value; 212 }); 213 var keys = array.map(result.rows,function(result){ 214 return result.key; 215 }); 216 if (options.get_keys === true) { 217 results = keys; 218 results.values = values; 219 } else { 220 results = values; 221 results.keys = keys; 222 } 223 dfd.resolve(results); 168 224 } 169 225 },function(err){ … … 175 231 176 232 function CouchResults(results) { 177 if (!results) { 178 return results; 233 results = QueryResults(results); 234 results.forPairs = function(callback,thisObject) { 235 callback = lang.hitch(thisObject,callback); 236 return Deferred.when(results,function(results) { 237 var values = results.values || results; 238 var keys = results.keys || results; 239 return array.forEach(values, function(value,index) { 240 callback(value,keys[index],index); 241 }); 242 }); 179 243 } 180 181 if(results.then){182 results = lang.delegate(results);183 }184 185 if (!results.forEach) {186 results.forEach = function(callback) {187 return Deferred.when(results, function(results) {188 array.forEach(results, function(result) {189 callback(result[1],result[0]);190 });191 });192 }193 }194 195 244 return results; 196 245 }
Note: See TracChangeset
for help on using the changeset viewer.