Created
December 1, 2012 02:23
-
-
Save alloyking/4180245 to your computer and use it in GitHub Desktop.
Sammy remote json load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//parse json plugin | |
(function($) { | |
Sammy.JSON.LoadJSON = function(app) { | |
app.helpers({ | |
loadJSON: function(location, options, callback) { | |
options = $.extend(options, {json: true}); | |
return new Sammy.RenderContext(this).load(location, options, callback); | |
} | |
}); | |
} | |
})(jQuery); | |
//app.js | |
Sammy('#main', function() { | |
this.use(Sammy.JSON.LoadJSON); | |
var app = $.sammy('#mytag', function() { | |
this.get('#/contact', function(context) { | |
this.loadJSON('http://samedomain/api/getdata') | |
.then(function(items) { | |
$.each(items, function(i, item) { | |
context.log(item); | |
}); | |
}); | |
}); | |
}); | |
}).run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment