2012-12-13 120 views
0

我正在使用ASP.Net MVC。我怎麼能轉換;=分隔字符串像Color=Red;Size=28;Price=45$;到HTML表所示:將字符串轉換爲表ASP.Net MVC

enter image description here

我希望用戶可以添加行表和編輯此類似:

enter image description here

和當用戶想要保存數據時,字符串更改爲Color=Red;Size=28;Price=45$;Tel=12345678。我嘗試了一些jQuery插件,如jtable,但我沒有成功。任何想法或解決方案?

回答

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