2011-08-03 5 views
0

다른 jquery 테이블의 레코드를 클릭하면 생성되는 jquery 테이블이 있습니다. 이 테이블의 레코드에는 입력하고 제출할 데이터가 있습니다. 표는 몇 개의 레코드로 구성됩니다. 제출 버튼을 클릭하면 테이블에있는 각 레코드가 레일 데이터베이스 테이블에 별도의 레코드 여야합니다. 어떻게하면 필요한 데이터를 가져와 데이터베이스에 제출할 수 있습니까? 테이블의 create 메서드가 필요하지만 할당 할 특성을 얻는 방법을 모른다. JQuery에서 레일즈 테이블로 여러 레코드 저장하기?

프로젝트 목록 표

<div class="right"> 

    <b>Projects this week</b><div class = "right"><input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();"></div> 

    <ul id="task_list"> 
     <form name="frmMain" method="post"> 
     <table width="470" border="1" id="tbExp"> 
      <tr> 
      <td><div align="center">No.</div></td> 
      <td><div align="center">Project </div></td> 
      <td><div align="center">Task </div></td> 
      <td><div align="center">Hours </div></td> 
      <td><div align="center"></div></td> 
      </tr> 
     </table> 

     <input type="hidden" name="hdnMaxLine" value="0"> 
     </form> 
    </ul> 
</div> 

에 javscript 프로젝트 목록 표

function CreateSelectOption(ele) { 
    var objSelect = document.getElementById(ele); 
    var Item = new Option("", ""); 
    objSelect.options[objSelect.length] = Item; 
    var Item = new Option("Pre-Sales"); 
    objSelect.options[objSelect.length] = Item; 
    var Item = new Option("Project"); 
    objSelect.options[objSelect.length] = Item; 
    var Item = new Option("Support"); 
    objSelect.options[objSelect.length] = Item; 
} 

function CreateNewRow(num, str) { 
    var intLine = parseInt(document.frmMain.hdnMaxLine.value); 
    intLine++; 

    var theTable = document.getElementById("tbExp"); 
    var newRow = theTable.insertRow(theTable.rows.length) 
    newRow.id = newRow.uniqueID 

    var newCell 

    //*** ID Column ***// 
    newCell = newRow.insertCell(0); 
    newCell.id = newCell.uniqueID; 
    newCell.setAttribute("className", "css-name"); 
    newCell.innerHTML = num; 

    //*** Column 1 ***// 
    newCell = newRow.insertCell(1); 
    newCell.id = newCell.uniqueID; 
    newCell.setAttribute("className", "css-name"); 
    //newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"10\" NAME=\"Column1_"+intLine+"\" ID=\"Column1_"+intLine+"\" VALUE=\"\"></center>"; 
    newCell.innerHTML = str; 

    //*** Column 2 ***// 
    newCell = newRow.insertCell(2); 
    newCell.id = newCell.uniqueID; 
    newCell.setAttribute("className", "css-name"); 
    newCell.innerHTML = "<center><SELECT NAME=\"Column5_"+intLine+"\" ID=\"Column5_"+intLine+"\"></SELECT></center>"; 

    //*** Column 3 ***// 
    newCell = newRow.insertCell(3); 
    newCell.id = newCell.uniqueID; 
    newCell.setAttribute("className", "css-name"); 
    newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column4_" + intLine + "\" ID=\"Column4_" + intLine + "\" VALUE=\"\"></center>"; 

    //*** Column 4 ***// 
    // newCell = newRow.insertCell(3); 
    // newCell.id = newCell.uniqueID; 
    // newCell.setAttribute("className", "css-name"); 
    // newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column4_"+intLine+"\" ID=\"Column4_"+intLine+"\" VALUE=\"\"></center>"; 

    //*** Column 5 ***// 
    //newCell = newRow.insertCell(4); 
    //newCell.id = newCell.uniqueID; 
    // newCell.setAttribute("className", "css-name"); 
    // newCell.innerHTML = "<center><SELECT NAME=\"Column5_"+intLine+"\" ID=\"Column5_"+intLine+"\"></SELECT></center>"; 

    //*** Create Option ***// 
    CreateSelectOption("Column5_" + intLine) 
    document.frmMain.hdnMaxLine.value = intLine; 
} 

function RemoveRow() { 
    intLine = parseInt(document.frmMain.hdnMaxLine.value); 
    if(parseInt(intLine) > 0) { 
     theTable = document.getElementById("tbExp"); 
     theTableBody = theTable.tBodies[0]; 
     theTableBody.deleteRow(intLine); 
     intLine--; 
     document.frmMain.hdnMaxLine.value = intLine; 
    } 
} 

CreateEfforts 마이그레이션

데이터

에 저장 될 필요가 어디

구성 파일

class CreateEfforts < ActiveRecord::Migration 
    def self.up 
    create_table :efforts do |t| 
     t.integer :project_task_id 
     t.integer :user_id 
     t.date :week_commencing 
     t.float :hours 

     t.timestamps 
    end 
    end 

    def self.down 
    drop_table :efforts 
    end 
end 

답변

0

보기에서 데이터를 추출하는 것에 대해 생각하십시오. 궁극적으로 당신의 생성 테이블이 레일 엔드 포인트에 당신이 $의 .post (를 통해 전송하는 jQuery를 함수에 전달할 수있는 tableList에 기록)를 추가 할 수

var myRecord = { number: 123, Project: 'name'... }; 
var tableList = []; 

: 당신은 같은 일부 데이터가 필요합니다. 그런 다음 tableList를 사용하여 페이지에서 표를 렌더링 할 수 있습니다.

관련 문제