-2
請幫助我!我如何組織這個邏輯
我想創建可編輯的數據表。在表格頂部將出現一個按鈕「添加」,用javascript將表添加到表中。並在每一行應該是butons(鏈接)「保存」和「刪除」。
我該如何向服務器發送發佈請求?
對不起,我的遲鈍..
在application.js中我有這樣
function AddElementsToPage(elements) {
/*elements - is array with name elements whose will be add to page*/
this.add_row_to_data_table = function(obj,attributes,selector_table){
last_row_of_table = selector_table.find('tbody tr').last();
var new_row = "<tr><th scope='row'></th>";
if ($.isEmptyObject(last_row_of_table.html()))
{
$.each(attributes, function(index, item){
input_tag = "<input id=\""+obj+"_"+item+"\" name=\""+obj+"["+item+"]\" size=\"10\" type=\"text\" />";
new_row = new_row + "<td>"+input_tag+"</td>";
})
alert(new_row);
selector_table.append(new_row+"</tr>");
}else
{
alert("not empty");
}
}
我的控制器動作新
def new
@table_row = SchOfWorkInformation.new
respond_to do |format|
format.js do
render :action => 'new'
end
end
end
我new.js一個函數文件
var obj = new AddElementsToPage();
obj.add_row_to_data_table("sch_of_working",["date","hour"], $('.data_table'))
我的我ndex.haml
= link_to content_tag('span', "Add" , :class=>"add"), new_sch_of_work_information_path, :remote => true
%table{:border=>"1", :class=>"data_table", :style=>"width:450px"}
%thead
%th{:style=>"width:5%;"} №
%th{:style=>"width:10%;"} Date
%th{:style=>"width:10%;text-align:center;"} schedule_code
%th{:style=>"width:2%;",:class=>"transperent_right_border"}
%th{:style=>"width:2%;"}
%tbody
%tr
%th{:scope=>"row"}
%[email protected]sch.date
%[email protected]_code
%td{:style=>"text-align:center"}= link_tag "save", sch_of_work_informations, #how can send post request in here
%td{:style=>"text-align:center"}
這是一個非常普遍的問題。請張貼一些代碼,告訴我們你已經嘗試了什麼,並詢問具體的事情。 – Utkanos 2012-07-31 10:52:58
Utkanos,我想創建可編輯的數據表。當我點擊表格頂部的按鈕添加時,它應該是添加輸入標籤的行。這行應該包含一個按鈕保存(或鏈接)。我現在不怎麼組織這個 – dilshod 2012-07-31 10:59:43
但是你沒有發佈任何代碼或者向我們展示了你正在做什麼。你有效地要求一個完整的解決方案,而這不是關於什麼。向我們展示您嘗試過的內容,如果您需要特定幫助,我們可以提供幫助。 – Utkanos 2012-07-31 11:01:13