Permalink
Browse files

Refactored the item loading code into a before block

  • Loading branch information...
1 parent b036644 commit 949646113f3ea9c5524a515f543bb36e3cf17ca2 @quirkey quirkey committed Oct 10, 2009
Showing with 17 additions and 6 deletions.
  1. +17 −6 javascripts/json_store.js
View
@@ -4,19 +4,30 @@
this.element_selector = '#main';
this.use(Sammy.Template);
- this.get('#/', function(context) {
+ this.before(function() {
+ // load the items
+ var context = this;
$.ajax({
url: 'data/items.js',
dataType: 'json',
+ async: false,
success: function(items) {
- $.each(items, function(i, item) {
- context.partial('templates/item.template', {item: item}, function(rendered) {
- context.$element().append(rendered);
- });
- });
+ context.items = items;
}
});
});
+
+ this.get('#/', function(context) {
+ $.each(context.items, function(i, item) {
+ context.partial('templates/item.template', {item: item}, function(rendered) {
+ context.$element().append(rendered);
+ });
+ });
+ });
+
+ this.get('#/item/:id', function(context) {
+
+ });
});

0 comments on commit 9496461

Please sign in to comment.