2016-03-01 56 views
0

我怎樣才能使這項工作:的Javascript替換/ GI和數組迭代器

 var storedValues = $('<table class="table_groessentabelle_custom"></table>'); 

     // contains excel paste content from Libreoffice 
     $('textarea[name=excel_data]').bind("paste", function(e){ 
      var pastedData = e.originalEvent.clipboardData.getData('text/html'); 
      storedValues.append(pastedData); 
     }); 

     //localisation - tables (just a subset) 
     var de = ["Größe","Höhe","Weite","Damen","Herren","Kinder",]; 
     var fr = ["Pointure","Hauteur","Largeur","Femme","Homme","Enfants"]; 

     var de_storedvalues = JSON.parse(JSON.stringify(storedValues.html())); 
     var fr_storedvalues = JSON.parse(JSON.stringify(storedValues.html())); 

     for (var i = 0; i < de.length; i++) { 
      // doesnt work, no fields are translated 
      fr_storedvalues = fr_storedvalues.replace(/de[i]/gi,fr[i]); 
     } 

其作品,未經/ GI標誌,但只有transates給定變量的第一個條目。如果有多個條目,其餘的保持爲德語。

由於提前,

邁克爾

回答

1
var find = de[i]; 
var regex = new RegExp(find, "g"); 
fr_storedvalues = fr_storedvalues.replace(regex,fr[i]);