callback param
で callback を通知することができる。
呼び出し側(index.html)
var tweets = $('#tweets'); tweets.bowlineChain('TweetsBinder'); $('#tweet').click(function() { Bowline.invoke("TweetsBinder", "sing" , "aaaa" , function(res){alert(res)}); Bowline.invoke("TweetsBinder", "sing" , ["aaaa" , "bbb" , "cccc"] , function(res){alert(res)}); Bowline.invoke("TweetsBinder", "sing" , {a:"A" , b:"B" , c:"C"} , function(res){alert(res.msg + " " + res.name)}); });
binder
class TweetsBinder < Bowline::Binders::Collection bind Tweet class << self def initial #[{:body => "Hello Tweet"}] klass.all end def sing(param) tweet = Tweet.new tweet.body = "sing #{param.class}" + param.to_s tweet.save if param.kind_of? String callback "success to tweet with string" elsif param.kind_of? Array callback ["success" , "to" , "tweet" , "with" , "array"] elsif param.kind_of? Hash ret = {:msg => "success to tweet with hash" , :name => "bowline"} callback ret end end end end
おもしろい。