weixin_33701294 2012-07-31 10:51 采纳率: 0%
浏览 20

我如何组织这种逻辑

Help me please!!

I want to create editable data table. In top of the table will be a button "Add" that adds row to the table with javascript. And in each row should be butons(links) "Save" and "Delete".

How can i send post request to server?

SORRY FOR MY dullness..

In application.js I have a function like this

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");
    }

}

my controllers action new

def new
 @table_row = SchOfWorkInformation.new
respond_to do |format|
  format.js do
    render :action => 'new'
  end
end
end

My new.js file

var obj = new AddElementsToPage();

obj.add_row_to_data_table("sch_of_working",["date","hour"], $('.data_table'))

My index.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"}
        %td=@sch.date
        %td=@sch.schedule_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"}
  • 写回答

1条回答 默认 最新

  • python小菜 2012-07-31 13:38
    关注

    I think this is the kind of answer you would be looking at. Follow the tutorial from railscasts http://railscasts.com/episodes/196-nested-model-form-part-1 nested form and it should help you. Basically you would have an add row button and it would add in javascript the html row, you could even have a remove the row button. Once this is done just press the save button of the form to allow all change to be done.

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题