나는 간단한 레일 앱을 통해 항목 목록을 표시하고 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'는 두 번째 제목을 출력합니다. 내 예제에서는 모든 반환 된 객체를 반복하는 방법을 보여줍니다. – Jasper