--- layout: old_post title: RESTアクセスを行うJavaScriptライブラリ Jester Ver.1.2の変更点 permalink: /tatsuya/show/320-rest-javascript-jester-ver-1-2 ---
Jester早速Ver 1.2出てたね、変更点をメモ
1) findがオプションでパラメータを受け付け、GETのクエリーストリングとして渡すように変更。
>>> User.find("all", {admin: true, toys: 5}) GET http://localhost:3000/users.xml?admin=true&toys=5
2) あわせてAjax用のコールバック関数も少し変更。三番目の引数としてハッシュを入れる、PrototypeのAjax.Requestと同じ形式でOK
>>> User.find("all", {admin: true, toys: 5}, {onSuccess: success, on404: notFound}) GET http://localhost:3000/users.xml?admin=true&toys=5
3) Base.model()もパラメータ少し変更、ハッシュで渡す
Base.model("User", {plural: "people", prefix: "http://www.thoughtbot.com"})
4) /リソース名/new.xml にアクセスしてオブジェクトの定義を取得するように変更。Rails側のこのパッチの件を反映
>>> eric = User.build({}, {checkNew: true}) GET http://localhost:3000/users/new.xml >>> eric._properties ["active", "email", "name"]
5) 日付形式のデータは暗黙的にDateオブジェクトへ変換する
>>> post.created_at Sat Mar 31 2007 03:01:56 GMT-0500 (Eastern Standard Time)
6) オブジェクト作成後、サーバ側で変更があった場合(XMLが帰ってきた場合)読み込みReloadするように変更
>>> eric = User.create({email: "emill@thoughtbot.com", name: "Eric Mill"}) POST http://localhost:3000/users.xml #結果として帰ってきたXMLでReload >>> eric.new_parameter "create_by_server"
JSONの読み込みをサポートしていないようなので組み込んでみようかと思ったけど、「次期バージョンで組み込む予定だ」と言ってるね。