가장 효율적인 방법은 아니지만 테이블에 대한 완성 된 HTML 부분을 Ajax 요청으로 반환하고 페이지에서 Div 컨테이너를 가져온 테이블로 다시 가져올 수 있습니다. 대부분의 경우 이것이 가장 쉬운 방법입니다. 단지 div의 내용을 바꾸는 것입니다. 당신의시나 주요 파일에
샘플 코드
조치 :
# some code
post "/path/to/your/action" do
# get the parameters you need and do the update operation, then:
@goods = Good.all # if you use activerecord, or use what you want to get the list
slim :goods_table # or haml or erb or ...
end
# some code
보기 파일 (내가 예를 들어 여기에 슬림 사용합니다) :
table
tr
th title
th price
th weight
th discount
- @goods.each do |good|
th
td = good.title
td = good.price
td = good.weight
td = good.discount
나는 당신의 테이블 인 가정 ID가 "상품 테이블"인 div에 배치됩니다. 따라서 jquery JS는 다음과 같을 것입니다 :
$.post("path/to/your/action", {parameter1: x, paramater2: y}, function (data) {
$("#goods-table").html(data);
});
아약스 # success에서 "partial (table_content_partial")을 호출하여 테이블을 렌더링해야한다고 생각합니다. 내가 어떻게 해? – Alexandre
jQuery 또는 고통스러운 일반 자바 스크립트를 사용합니까? – Hisako
나는 무엇이든을 사용할 수있다, 상관 없습니다. 그래서 Sinatra 메서드에서 "완성 된 HTML 부분"을 반환합니까? – Alexandre