Skip to content

Instantly share code, notes, and snippets.

@ttdonovan
Created April 29, 2009 15:38
Show Gist options
  • Select an option

  • Save ttdonovan/103848 to your computer and use it in GitHub Desktop.

Select an option

Save ttdonovan/103848 to your computer and use it in GitHub Desktop.
fetchRecords: function(store, fetchKey, params) {
var ret = [], idx, len, id, recordType, rec, url, request, datasource ;
datasource = this ;
len = params.length ;
for(idx = 0; idx < len; idx++) {
storeKey = params[idx] ; // storeKey
id = store.idFor(storeKey) ; // record id
recordType = store.recordTypeFor(storeKey) ;
rec = store.find(recordType, id) ; // specific record found by id
url = rec.get('resourceURL') ; // resource url
ret.push(storeKey) ; // return array of storeKeys
request = SC.Request.getUrl(url) ;
request.set('isJSON', YES) ;
request.addObserver('response', function(r) { datasource.fetchRecordsDidComplete(r, store, storeKey)}) ;
request.send() ;
}
return ret; // return array of storeKeys
},
fetchRecordsDidComplete: function(r, store, storeKey) {
var response ;
response = r.response() ;
store.dataSourceDidComplete(storeKey, response) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment