Created
January 16, 2012 12:39
-
-
Save yurfuwa-chan/1620681 to your computer and use it in GitHub Desktop.
spine ajax sample
This file contains hidden or 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
$ = jQuery | |
class AjaxModel extends Spine.Model | |
@configure "AjaxModel" ,"data" | |
@updateOrder : -> | |
url = "http://search.twitter.com/search.json?callback=?" | |
query = q :escape("javascript") | |
$.getJSON(url,query,(d)=> | |
AjaxModel.create({data:d}) | |
) | |
class ExampleModel extends Spine.Model | |
@configure "ExampleModel" , "val" | |
class ExampleApp extends Spine.Controller | |
events : | |
"click .test" : "test" | |
elements: | |
".test" : "test" | |
constructor: -> | |
super | |
ExampleModel.bind("create",@add) | |
AjaxModel.bind("create",(_model)=> | |
console.log _model | |
for obj in _model.data.results | |
@el.append("<p>#{obj["text"]}</p>") | |
console.log "complete" | |
) | |
test: => | |
AjaxModel.updateOrder(); | |
add: (_model)=> | |
console.log(_model) | |
@el.append("<p>hogehoge</p>") | |
$ -> | |
new ExampleApp(el:$("#wrap")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment