シンプルなレールアプリがあり、jquery mobileを使ってネイティブモバイルアプリを作成したいと思っています。 私のコントローラはjquery mobileとjson in Railsを使用する
class ListsController < ApplicationController
respond_to :json
def index
@lists = List.all
respond_with(@lists)
end
# ...
end
はその後、私のネイティブモバイルアプリに私は私のindex.htmlページにこれを持っている
$.ajax({
url: "http://localhost:3000/lists",
dataType: "json",
type: "GET",
processData: false,
contentType: "application/json"
});
このデータがフェッチされ、私はそれがjQueryのモバイルテンプレートに追加されたいですliのタブの内側にあります。どのようにjqueryを使用してこれを行うことができます。
$.ajax({
url: "http://localhost:3000/lists",
dataType: "json",
type: "GET",
processData: false,
contentType: "application/json",
success: function(transport){
insertMyStuff(transport);
}
});
私は外のコールバック・ロジックを動かすのが好き:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Simple test app</h1>
</div>
<div data-role="content">
<ul>
<li>(content appends here)</li>
</ul>
</div>
<div data-role="footer">
<h4>test app</h4>
</div>
</div>
</body>
</html>
JSONの出力例は
何あなたのJSON出力はありませんどう?あなたは例を投稿できますか? – Jasper
ちょうどそれをuopated – Uchenna
あなたのJSON出力を反映するために私の答えを更新しました。 'serverResponse [0] .list.title'は最初のタイトルを出力し、' serverResponse [1] .list.title'は2番目のタイトルを出力します。私の例は、返されたすべてのオブジェクトを反復処理する方法を示しています。 – Jasper