问题
What is the correct way to cache this callback value when doing a backbone fetch? Have tried overiding the fetch function and setting
options.cache = true;
but no avail.
Ideally we want to continue using fetch, and not write a custom ajax call. The below is an example of the callback parameter that is being appended. I need this to be the same return value each time, i.e so it's acting as a cache.
&callback=jQuery1111042059096531011164_1421344480838&_=1421344480840
If more detail is needed please let me know,
Many thanks.
回答1:
You could use the local storage
if (!myData) {
myCollection.fetch({
success: function( data ) {
localStorage.setItem('myData', JSON.stringify(data));
}
});
} else {
myCollection.set(myData);
}
回答2:
FYI.
The solution that appears so far to have worked was to not override the fetch but override the sync and hardcode a string as the jsonPCallback such as below.
sync: function(method, model, options){
options.dataType = this.SYNC_METHOD;
options.cache = true;
options.jsonp = 'callback';
options.jsonpCallback = "onNowCallback";
return Backbone.sync(method, model, options);}
来源:https://stackoverflow.com/questions/27981774/caching-jsonp-callback-parameter-when-doing-a-backbone-fetch