Skip to content

Instantly share code, notes, and snippets.

@yurfuwa-chan
Created January 16, 2012 12:39
Show Gist options
  • Save yurfuwa-chan/1620681 to your computer and use it in GitHub Desktop.
Save yurfuwa-chan/1620681 to your computer and use it in GitHub Desktop.
spine ajax sample
$ = 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