2012-12-13 2 views
0

ASP.Net MVC를 사용하고 있습니다. 어떻게 테이블처럼 HTML로 Color=Red;Size=28;Price=45$; 같은 ;= 구분 된 문자열로 변환 할 수 있습니다 : 나는 사용자가 테이블에 행을 추가하고 편집 할 수 원하는문자열을 테이블로 변환 ASP.Net MVC

enter image description here

이 같은 :

enter image description here

및 사용자가 데이터를 저장하려고 할 때 문자열이 Color=Red;Size=28;Price=45$;Tel=12345678으로 변경됩니다. jtable 같은 일부 jQuery 플러그인을 시도했지만 성공하지 못했습니다. 어떤 아이디어 또는 해결책?

당신은 같은 테이블에 문자열을 변환 할 수 있습니다

답변

0

:

// Remove the final ; if one exists: 
if (tableString.substring(tableString.length - 1) == ';') { 
    tableString = tableString.substring(0, tableString.length - 1); 
} 

var tableHtml = 
    "<table><tr><td>" + 
    tableString // where table string is something like 'Color=Red;Size=28;Price=45$' 
     .replace(";", "</tr><tr>") 
     .replace("=", "</td><td>") + 
    "</td></tr>"; 

... 그리고 테이블을이 같은 문자열 (사용 JQuery와)에 :

var tableString = 
    $("table tr").each(function() { 
     return $(this).children("td").text().join("="); 
    }) 
    .join(";"); 
관련 문제