2012-12-13 74 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(";");