javascript - Fetch backbone collection from remote url error -


i'm trying set model using backbone loads remote url: https://api.github.com/legacy/repos/search/javascript. here have far.

var repo= backbone.model.extend({});  var repocollection = backbone.collection.extend({     url : "https://api.github.com/legacy/repos/search/javascript",     model : repo });   var repos = new repocollection();  repos.fetch({success: function(){     console.log(repos.models); }}); 

this gives me empty array. why not work? url contains non-empty json array. i've tried parse function without success.

parse : function(data) {    return data.results; } 

if github api not support kind of call, have example of remote url can use backbone fetch data?

edit: should add looked @ network console on chrome , getting 200 ok response correct json response github. guess i'm having trouble figuring out how access data , populate repocollection it.

your data wrapped in repositories key, not in results , looks this

{     "repositories": [         ...     ] } 

try

var repocollection = backbone.collection.extend({     url : "https://api.github.com/legacy/repos/search/javascript",     model : repo,      parse : function(data) {         return data.repositories;     } }); 

and demo http://jsfiddle.net/nikoshr/vhx7c/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -