jquery ui 1.9.0 autocomplete autofocus not working - jquery-ui

Antecedents:
jquery-ui-1.9.0.custom.min.css
jquery-1.8.2.js
jquery-ui-1.9.0.custom.min.js
The code is as follows:
$("#origen, #destino").autocomplete({
source: function(request, response){
$("#cargando").show();
// Para distinguir la cache del elemento origen y destino ya que van a jsp's diferentes. tolo (03/07/2012)
var term = request.term; var termCache = request.term + "-" + $(this.element).attr("id");
if ( termCache in cache ) {
response( cache[ termCache ] );
setTimeout("$('#cargando').hide();", 2000);//ocultamos con retraso 2 seg
return; }
if($(this.element).attr("id") == "origen"){
// El filtro de aeropuertos por pais es solo para el origen
if (parent.codMarca == 'NET')
paises = '|PT|ES|';
urlxx = "../../jsp/buscador/autocompletevuelos.jsp?sesion=" + sesion + "&term=" + term + "&codidi=" + codidi +
"&tipPro=VH&paises=" + codpai + "&codEmp=" + parent.codEmp + "&codMarca=" + parent.codMarca + "&codWcn=" +
parent.codWcn + "&orides=O"; }else{
urlxx = "../../jsp/buscador/autocompletepoblaciones.jsp?sesion=" + sesion +
"&term=" + term +
"&codidi=" + codidi +
"&tipoProducto=VH&codemp=" + codEmp +
"&codwcn=" + codWcn + "&codMarca=" + parent.codMarca; }
lastXhr = $.getJSON( urlxx, request, function( data, status, xhr ) {
cache[ termCache ] = data;
if ( xhr === lastXhr ) {
response( data );
setTimeout("$('#cargando').hide();", 2000);//ocultamos con retraso 2 seg
}
});
},
minLength: 2,
select: function(event, ui) {
var componente = $(this).attr("id");
if (ui.item) {
// El check de residente sólo tiene que estar habilitado cuando los dos aeropuertos son españoles, y al menos uno de ellos
// consta como residente.
if(componente == "origen"){
$("#oriCodApt").val(ui.item.id);
$("#orideszona").val(ui.item.value);
$("#oricodpai").val(ui.item.codpai.toUpperCase());
$("#oriresidente").val(ui.item.residente.toUpperCase());
}else{
$("#desCodApt").val(ui.item.codapt);
$("#desdeszona").val(ui.item.value);
$("#descodpai").val(ui.item.codpai.toUpperCase());
$("#desresidente").val(ui.item.residente.toUpperCase());
$("#zonaCodificada").val( ui.item.codpai.toUpperCase() + "#" +
ui.item.codepr.toUpperCase() + "#" +
ui.item.codpob.toUpperCase() + "#" +
ui.item.codare.toUpperCase());
$("#numAeropuertos").val(ui.item.numAeropuertos == undefined ? 0 : ui.item.numAeropuertos);
$("#fueraCiudad").val(ui.item.fueraCiudad == undefined ? "" : ui.item.fueraCiudad);
}
validaResidente();
}
},
open: function(e,ui) {
var autoData = $(this).data('autocomplete');
var reserText = ",de,del,el,la,las,los,en,";
var altoCombo = 200; // Altura del combo del autocomplete.
var componente = $(this).attr("id");
autoData.menu.element.css({'width':'' + anchoMinimo + 'px'});
autoData.menu.element.find('li').each(function() {
var fila = $(this);
var texto = fila.text().toLowerCase().replace(autoData.term.toLowerCase(), "<b>" + autoData.term.toLowerCase() + "</b>");
var autoText = "";
texto = texto.split(" ");
for(var i = 0; i < texto.length; i++){
if((reserText.indexOf( texto[i].replace("<b>","").replace("</b>","") ) != "-1") && (i > 0)){
autoText += texto[i] + " ";
}else if( texto[i].substring(0,3) == "<b>" ){
autoText += "<b>" + texto[i].charAt(3).toUpperCase() + texto[i].substring(4) + " ";
}else{
autoText += texto[i].charAt(0).toUpperCase() + texto[i].substring(1) + " ";
}
}
autoText = autoText.replace(" De "," de ").replace(" Del "," del ").replace(" Los "," los ").replace(" El "," el ").replace(" En "," en").replace(" La "," la ").replace(" Las "," las ");
// El código de aeropuerto, lo que va entre paréntesis, tiene que salir en mayúsculas.
if(componente == "origen"){
var tamPrimerCorte = autoText.split("(").length;
var textoEnParentesis = autoText.split("(")[tamPrimerCorte - 1];
textoEnParentesis = textoEnParentesis.split(")")[0];
autoText = autoText.replace("(" + textoEnParentesis + ")", "(" + textoEnParentesis.toUpperCase() + ")");
}
fila.find('a').text("");
fila.find('a').append( autoText );
// Ahora vamos a calcular el ancho de la cadena más ancha para saber qué ancho tiene que tener el combo.
ancho = autoText.length * 5; // Con esta fuente de letra, en IE, etc...
if(ancho > anchoFilaDestinos){
anchoFilaDestinos = ancho;
}
// Fin del cálculo del ancho.
fila.find('a').css({'white-space':'nowrap'});
});
// Hay que mantener un ancho mínimo.
if(anchoFilaDestinos < anchoMinimo){
anchoFilaDestinos = anchoMinimo;
}
numItems = 0;
// Hay que recorrer todas las filas otra vez, para ponerles a todas el mismo ancho.
autoData.menu.element.find('li').each(function() {
var fila = $(this);
fila.find('a').css({'white-space':'nowrap','width':'' + anchoFilaDestinos + 'px','text-align':'left'});
numItems++;
});
anchoFilaDestinos += 9;
autoData.menu.element.css({'width':'' + anchoFilaDestinos + 'px'});
anchoFilaDestinos = 0;
// Porque 9 son los que caben en 200 de alto.
if(numItems < 9){
altoCombo = numItems * 23;
$(".ui-autocomplete").css("height", altoCombo).css("overflow-y", "hidden").css("overflow-x", "hidden");
}else{
$(".ui-autocomplete").css("height", altoCombo).css("overflow-y", "scroll").css("overflow-x", "hidden");
}
},
error : function() {
if ( $(this).attr("id") == "origen" ){
parent.crearModal('Alerta', '<ml:message id="1" value="Hay un error en la peticion de ORIGEN."/>');
} else {
parent.crearModal('Alerta', '<ml:message id="2" value="Hay un error en la peticion de DESTINO."/>');
}
},
autoFocus: true,
focus: function(event, ui){
if (ui.item) {
var codzon = "P:" + ui.item.codpai + "#" + ui.item.codepr + "#" + ui.item.codpob + "#" + ui.item.codare;
if($(this).attr("id") == "origen"){
$("#oricodzona").val(codzon);
$("#orideszona").val(ui.item.value);
}else{
$("#descodzona").val(codzon);
$("#desdeszona").val(ui.item.value);
}
} else {
if($(this).attr("id") == "origen"){
$("#oricodzona").val("");
}else{
$("#descodzona").val("");
}
}
}
});
Finally, as you can see, the option autoFocus:true, but it doesn't work, even the list is filled up correctly.
Please, any help?

Ok, autoanswering: you must delete de selectFirst clause before including the autoFocus.

Related

How to create and send a table by grouping rows by email addresses - GoogleSheets

I need help to create a table, from column [B] to column [I] if the emails from the managers of column [J] are the same:
Example_01
The yellow lines have the same manager in column [J]: "rafalmfei#gmail.com", so I need to set up a single email with a table, for the manager (Column [J2] and [J3]) with a copy for o Partner E-mail "rafaalmeida_feitoa#yahoo.com.br" (column k 2 and k 3) with lines 2 and 3.
Example_02
And an email with another separate table for the manager "rafaalmeida_feitoa#yahoo.com.br", (column [4] and column [5]) with a copy for Partner E-mail "rafalmfei#gmail.com" (column k [4] and k [5]) with lines 4 and 5.
Example_03
Currently, I have the email ready with the code below, but I receive the lines in separate emails, I need it to be in a single email in table format:
function enviarEmailJornada(){
// Linka a planilha de controle ao script e pega todas as colunas existentes
var planilha = SpreadsheetApp.getActive();
var sheet = planilha.getSheetByName("Analise_Maio");
var linhas = sheet.getRange(1, 1, 156).getValues();
var colunas;
// Cria as variáveis necessárias para enviar o e-mail
var toEmail;
var ccEmail;
var subject = "[URGENTE] Análise imediata de projetos sem ETC";
var message;
// Percorre as linhas da tabela e busca os dados de cada coluna
for(var i = 0; i < linhas.length; i++){
colunas = sheet.getRange(i+1,1,1,sheet.getLastColumn()).getValues()[0];
toEmail = colunas[9];
ccEmail = colunas[10];
if(colunas[0] == "1"){
message = "Caro(a), <br><br>";
message += "Identificamos que os projetos abaixo apresentam ETC zero e estão em seu nome. <br><br>";
message += "Adicionalmente, elencamos projetos que estão com ETC Zerado e que o valor faturado é inferior a 0% da última valorização do WIP, o que pode indicar um risco em relação à realização destes valores. <br><br>";
message += "<br>————————————<br><br> " + " "+ colunas[1] +" " + colunas[2] + " " + colunas[3] + " " + colunas[4] + " " + colunas[5] + " " + colunas[6] + " " + colunas[7] + " " + colunas[8] + " " +"<br><br><br>";
message += "Peço a gentileza de que efetuem a imediata análise, reportando diretamente aos sócios dos projetos, a razão destas inconsistências. <br><br>";
message += " Adicionalmente, como já diversas vezes solicitado, peço que efetuem imediatamente as baixas dos projetos cujo trabalho já foi concluído (ETC Zero) e valores faturados.<br><br>";
message += "Conto com a sua pronta atuação. <br><br>";
message += "Rafaela Feitosa <br><br>";
GmailApp.sendEmail(toEmail,subject,"",{cc: ccEmail, htmlBody: message, name: "Análise imediata de projetos sem ETC"});
}
}
}
Thank you!
You can do the following
Retrieve all managers from the sheet
Use ...new Set() to retrieve unique values of managers
For each distinct manager retrieve the relevant sheet values and push them into an html table
Send an email after iterating through all rows and retrieving all data for particular manager
SAMPLE
function enviarEmailJornada(){
// Linka a planilha de controle ao script e pega todas as colunas existentes
var planilha = SpreadsheetApp.getActive();
var sheet = planilha.getSheetByName("Analise_Maio");
// Cria as variáveis necessárias para enviar o e-mail
var subject = "[URGENTE] Análise imediata de projetos sem ETC";
var message;
var colunas = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn()).getValues();
var managers = sheet.getRange(1, 8, sheet.getLastRow()).getValues().flat();
Logger.log(managers);
var uniqueManagers = [...new Set(managers)];
Logger.log(uniqueManagers);
uniqueManagers.forEach(myFunction);
function myFunction(manager) {
var table = "<table>"
var toEmail = "";
var ccEmail = "";
// Percorre as linhas da tabela e busca os dados de cada coluna
for(var i = 0; i < colunas.length; i++){
if(colunas[i][7] == manager && colunas[i][0] == "1"){
toEmail = colunas[i][9];
ccEmail = colunas[i][10];
table += "<tr><td>"+ colunas[i][1] +"</td><td>" + colunas[i][2] + "</td><td>" + colunas[i][3] + "</td><td>" + colunas[i][4] + "</td><td>" + colunas[i][5] + "</td><td>" + colunas[i][6] + "</td><td>" + colunas[i][7] + "</td><td>" + colunas[i][8] + " " +"</td></tr>";
}
}
Logger.log("table"+ table);
if(toEmail != ""){
message = "Caro(a), <br><br>";
message += "Identificamos que os projetos abaixo apresentam ETC zero e estão em seu nome. <br><br>";
message += "Adicionalmente, elencamos projetos que estão com ETC Zerado e que o valor faturado é inferior a 0% da última valorização do WIP, o que pode indicar um risco em relação à realização destes valores. <br><br>";
message += "<br>————————————<br><br> "
message += table + "</table>";
message += "<br><br><br>";
message += "Peço a gentileza de que efetuem a imediata análise, reportando diretamente aos sócios dos projetos, a razão destas inconsistências. <br><br>";
message += " Adicionalmente, como já diversas vezes solicitado, peço que efetuem imediatamente as baixas dos projetos cujo trabalho já foi concluído (ETC Zero) e valores faturados.<br><br>";
message += "Conto com a sua pronta atuação. <br><br>";
message += "Rafaela Feitosa <br><br>";
GmailApp.sendEmail(toEmail,subject,"",{cc: ccEmail, htmlBody: message, name: "Análise imediata de projetos sem ETC"});
}
}
}
References:
flat()
Set()
Spread

GAS : How to check if a file exists in a specific folder and if so go to the next iteration

I'm writing a script that does the following :
send an email with an attachment (eg proof of payment) to people that register for our event when two criteria are met: payment has been processed, and if they have not yet received their proof of payment
make a copy of an existing file, using some variables in the new copy (this works fine) to personalize the proof of payment.
The copy of the file gets a new name (personalized).
I seem to be unable to make the script check correctly if the file already exists or not.
Who can help me out ?
function createDocument(e) {
var headers = Sheets.Spreadsheets.Values.get('SHEET ID', 'Lijst!A1:G');
var lid = Sheets.Spreadsheets.Values.get('SHEET ID', 'Lijst!A2:G');
var templateId = 'TEMPLATE ID';
for (var j = 0; j < lid.values.length; j++) {
if (lid.values[j][6] == 'ok' && lid.values[j][7] != 'Bewijs Verzonden') {
//collect the data from the member
var voornaam = lid.values[j][0];
var familienaam = lid.values[j][1];
var email = lid.values[j][2];
var aantal = lid.values[j][3];
var betaaldop = lid.values[j][5];
//Make a copy of the template file
var documentId = DriveApp.getFileById(templateId).makeCopy().getId();
var doc = DriveApp.getFileById(documentId);
var docname = 'Betalingsbewijs Reunie 2019 voor ' + familienaam + ' ' + voornaam + '.pdf';
//var filecheck = DriveApp.getFolderById('FOLDER ID');
var filecheck = DriveApp.getFilesByName(docname);
if (filecheck.hasNext()) {
Logger.log("No File Found");
} else {
//Get the document body as a variable
var body = DocumentApp.openById(documentId).getBody();
//Insert the data from spreadsheet
body.replaceText('<<Voornaam>>', voornaam)
body.replaceText('<<Naam>>', familienaam)
body.replaceText('<<Aantal deelnemers>>', aantal)
body.replaceText('<<Betaald op>>', betaaldop)
DocumentApp.openById(documentId).saveAndClose();
//move file to new folder and remove from parent folder
var file = DriveApp.getFileById(documentId);
file.getParents().next().removeFile(file);
DriveApp.getFolderById('FOLDER ID').addFile(file);
var pdfname = file.setName('Betalingsbewijs Reunie 2019 voor ' + familienaam + ' ' + voornaam + '.pdf');
var steil = "email#gmail.com";
var blob = pdfname.getBlob().getAs('application/pdf');
var subject = 'Betalingsbewijs Reunie 2019 voor ' + familienaam + ' ' + voornaam + ' met ' + aantal + 'deelnemer(s)';
var htmlBody =
"Beste " + voornaam + ", " +
"<br/>" +
"<br/>" +
"<br/>Bedankt voor uw inschrijving voor de Steil reünie op zaterdag 26 januari 2019." +
"<br/>Wij hebben uw betaling goed ontvangen." +
"<br/>Uw deelname aan de reünie is nu definitief in orde." +
"<br/>In bijlage kan u uw betalingsbewijs terugvinden in pdf." +
"<br/><br/>Indien u nog vragen heeft kan u ons steeds bereiken via reunie.steil#gmail.com." +
"<br/>Met verplegende groeten," +
"<br/>Het Steil Reünie team";
var optAdvancedArgs = {
name: "Steil Reünie 2019",
htmlBody: htmlBody,
replyTo: email,
cc: steil,
attachments: [blob]
};
GmailApp.sendEmail(email, subject, body, optAdvancedArgs);
var ConfirmationRange = "Lijst!H" + [j + 2];
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(ConfirmationRange).setValue('Bewijs Verzonden');
}
}
}
}

The Range.getValue method is widely used by the script an execution hint(the light bulb in the menu)

Hello I wrote a script that complets several Google Docs tables with values from different columns in a Spreadsheet.
I declared the columns variables : (8 in total)
var colonne_nom_de_projet = 3
var colonne_code_de_projet = 1
var colonne_chef_de_projet = 7
var colonne_service_pilote_de_projet = 8
var colonne_autres_services_projet = 11
var colonne_typede_projet = 10
var colonne_perimetre__projet = 12
var colonne_date_de_projet = 18
and var NUMERO_COLONNE_2019 = 2;
so the name of the project is in the third column ... and the date in 18 column and I want to create a doc only if I have yes in the second columnAfter that I started to complete my Google Doc table with this values
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
var data = sheet.getDataRange().getValues();
var targetFolder = DriveApp.getFolderById(FOLDER_ID);
Logger.log('targetFolder name: ' + targetFolder.getName());
var numRows=sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var nombre_projets_2019 = 0 ;
// à partir de 2 car la première ligne ne nous interesse pas
for(n=2;n<=data.length;++n) {
if (sheet.getRange(n,NUMERO_COLONNE_2019).getValue() == 'yes'){
if(child.getType()==DocumentApp.ElementType.TABLE && child.asTable().getNumRows() >= 8)
{
child.asTable().getCell(0, k).editAsText().setText( sheet.getRange(n,colonne_nom_de_projet).getValue() );
child.asTable().getCell(1, k).editAsText().setText( sheet.getRange(n,colonne_code_de_projet).getValue() ) ;
child.asTable().getCell(2, k).editAsText().setText(sheet.getRange(n,colonne_chef_de_projet).getValue()) ;
child.asTable().getCell(3, k).editAsText().setText( sheet.getRange(n,colonne_service_pilote_de_projet).getValue() ) ;
child.asTable().getCell(4, k).editAsText().setText( sheet.getRange(n,colonne_autres_services_projet).getValue() ) ;
child.asTable().getCell(5, k).editAsText().setText( sheet.getRange(n,colonne_typede_projet).getValue() ) ;
child.asTable().getCell(6, k).editAsText().setText( sheet.getRange(n,colonne_perimetre__projet).getValue() ) ;
child.asTable().getCell(7, k).editAsText().setText( sheet.getRange(n,colonne_date_de_projet).getValue() ) ;
and it works but I have a message and an execution hint(the light bulb in the menu)
"The Range.getValue method is widely used by the script.CollapseFile:
Code Line: 75The script uses a method that is considered expensive.
Each invocation generates a long-term call to a remote server. This
can have a critical impact on script execution time, especially on
large data. If the script has a performance problem, we recommend that
you use another method, such as Range.getValues ()." If you have any ideas it will be great ^^^^ because line 75 corresponds to
if (sheet.getRange(n,NUMERO_COLONNE_2019).getValue() == 'yes')
Edit edit : this is my very very slow code 4 minutes
function create_Google_Docs_2019_0() {
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
var numRows = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var data = sheet.getRange(1,1,numRows,lastColumn).getValues()
var targetFolder = DriveApp.getFolderById(FOLDER_ID);
Logger.log('targetFolder name: ' + targetFolder.getName());
var numRows=sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var nombre_projets_2019 = 0 ;
// à partir de 2 car la première ligne ne nous interesse pas
for(n=1;n < data.length;n++) {
//verifier si c'est une projet 2019 >>>>>>>>>>>>>>>>>>> ici on fait notre travail
if ( data[n][1] == 'o'){
nombre_projets_2019 = nombre_projets_2019 + 1;
var nom_projet = data[n][2];
//var nom_document = 'Projet ' + nom_projet ;
var nom_document = nom_projet ;
/** Recherche si dans folder il y a déjà ce fichier avec ce nom on va l'actualiser avec les données changés**/
if( checkFile_in_a_Folder(nom_document,targetFolder) == 1){
//on ajoute le fichier dans le repertoire courant targetFolder
Logger.log('On va réecrire le ficher / overwrite le ficher ');
}
else
{
Logger.log('On va le créer avec les données qu on a dans le tableau ');
//Make a copy of the template file
var documentId = DriveApp.getFileById(TEMPLATE_DOC_ID).makeCopy().getId();
//Rename the copied file
var name = DriveApp.getFileById(documentId).setName(nom_document);
var body = DocumentApp.openById(documentId).getBody();
if(body)
{
var ok = 0; //pour l'instant il n'y a pas de tableau
var numChildren=body.getNumChildren();
var i=0;
//tant qu'on n'a pas du tableau on va parcourir
while(ok ==0 && i<numChildren)
{
var child=body.getChild(i);
/** ============On est concerné par le premier tableau seulement qui a au plus 8 lignes d'information ================**/
Logger.log('Le type dans la boucle ' + child.getType());
//on a trouvé un tableau
if(child.getType()==DocumentApp.ElementType.TABLE && child.asTable().getNumRows() >= 8)
{
//on a trouve notre premier tableau
ok=1;
var numrows = child.asTable().getNumRows();
Logger.log('Le nombre de lignes dans notre Google Doc ' + numrows);
var insertion_position = n ;
Logger.log('Position pour inserer dans le spreadsheet ' + insertion_position);
var k = 1;
child.asTable().getCell(0, k).editAsText().setText( data[n][colonne_nom_de_projet-1]);
child.asTable().getCell(1, k).editAsText().setText( data[n][colonne_code_de_projet-1] ) ;
child.asTable().getCell(2, k).editAsText().setText( data[n][colonne_chef_de_projet-1]) ;
child.asTable().getCell(3, k).editAsText().setText( data[n][colonne_service_pilote_de_projet-1] ) ;
child.asTable().getCell(4, k).editAsText().setText( data[n][colonne_autres_services_projet-1] ) ;
child.asTable().getCell(5, k).editAsText().setText( data[n][colonne_typede_projet-1] ) ;
child.asTable().getCell(6, k).editAsText().setText( data[n][colonne_perimetre__projet-1] ) ;
child.asTable().getCell(7, k).editAsText().setText( data[n][colonne_date_de_projet-1] ) ;
}
i++;
}
}
}
}
Logger.log('Nombre de projets 2019 ' + nombre_projets_2019 );
}
}
it's a project so that by searching in the second column for 'o' (oui in French) means that the project will be in 2019 so i will get the information from several columns i want(name project,date,chef de project...) and then put this information in a Google Doc Table created using a Template with makecopy() with 8 rows and 2 columns so all the information will be put in the second colum.In fact my code is very slow and if you have any ideas to improuve it will be great because it does the work in about 4 min
Use range.getValues() to get the values in an array (single call to API), instead of using .getValue() multiple times (multiple calls, 'considered expensive').
Instead of:
for(n=2;n<=data.length;++n) {
child.asTable().getCell(0, k).editAsText().setText( sheet.getRange(n,colonne_nom_de_projet).getValue() );
child.asTable().getCell(2, k).editAsText().setText(sheet.getRange(n,colonne_chef_de_projet).getValue()) ;
//etc.
Use:
var values = sheet.getRange(0,0,20,20).getValues() //or whatever the range is
for(n=2;n<=data.length;++n) {
child.asTable().getCell(0, k).editAsText().setText( values[n][colonne_nom_de_projet]) );
child.asTable().getCell(2, k).editAsText().setText(values[n][colonne_chef_de_projet])) ;
//etc.
Something like that, you get the idea.

Delete only some char from a string

I want to delete only ',' which are located before ']'. I tried with:
arbre={"name":"flare","children":[{"name":"Algèbre","children":[{"name":"Nombres
Fractionnels","children":[{"name":"Addition
fractionnelle","size":8.333333333333334},{"name":"Division
fractionnelle","size":10.0},]},{"name":"nombre
entier","children":[{"name":"division
entière","size":15.0},]},]},{"name":"Geometrie dans
l'espace","children":[{"name":"projection dans
l'espace","children":[{"name":"sous chapitre1 projection dans
l'espace","size":10.0},{"name":"sous chapitre2 projection dans
l'espace","size":15.0},]},]},{"name":"Physique","children":[{"name":"Onde","children":[{"name":"Onde
circulaire","size":15.0},]},]},]}
for(i=0; i<arbre.length(); i++) {
if (( arbre[i] == ',') && (arbre[i+1] == ']' )){
arbre = arbre.replace(arbre[i],'')
}
}
println"nouveauarbre="+arbre
But with this code all ',' are delete and not only which are located before ']':
nouveauarbre={"name":"flare""children":[{"name":"Algèbre""children":[{"name":"Nombres
Fractionnels""children":[{"name":"Addition
fractionnelle""size":8.333333333333334}{"name":"Division
fractionnelle""size":10.0}]}{"name":"nombre
entier""children":[{"name":"division
entière""size":15.0}]}]}{"name":"Geometrie dans
l'espace""children":[{"name":"projection dans
l'espace""children":[{"name":"sous chapitre1 projection dans
l'espace""size":10.0}{"name":"sous chapitre2 projection dans
l'espace""size":15.0}]}]}{"name":"Physique""children":[{"name":"Onde""children":[{"name":"Onde
circulaire""size":15.0}]}]}]}
Did you try:
arbre = arbre.replaceAll(",]", " ]")
Try replacing ,] with ].
",]".replaceAll(",]", "]") // ""
",],".replaceAll(",]", "]") // ","
",],,".replaceAll(",]", "]") // ",,"
arbre.replaceAll(",]", "]")
Try here.

I get false lat long for the cities of Dom-Tom when i use geocoder google

my script
<script type="text/javascript">
// ....
//....
var adresse = jQuery.trim(region) + ", " +jQuery.trim(adresse) + ", " + jQuery.trim(codePostal) + ", " + jQuery.trim(ville) + ", " + jQuery.trim(pays);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: adresse, region: 'no' },
function (coords, status) {
if (status.toLowerCase() == 'ok') {
var lat = coords[0].geometry.location.lat();
var lon = coords[0].geometry.location.lng();
console.log("lat :"+lat+", lon :"+lon);
}
else {
alert("address not found");
}
} );
</scrip>
I have a problem latlong the region dom-tom of France, I have latlong false when I insert this address
"La Réunion, 9 Rue des Poivriers, 97400, Saint-Denis, France"
I like latlong => (lat: 48.936181, lon: 2.3574429999999893) but it's false
I hope someone has a solution, if so thank you for helping me
(Sorry about my english!)
I found the solution finally just eliminate the country for overseas regions
like that :
<script type="text/javascript">
// ....
//....
if(jQuery.trim(pays) == 'France'){
var adresse = jQuery.trim(region) + ", " +jQuery.trim(adresse) + ", " + jQuery.trim(codePostal) + ", " + jQuery.trim(ville);
}
else{
var adresse = jQuery.trim(region) + ", " +jQuery.trim(adresse) + ", " + jQuery.trim(codePostal) + ", " + jQuery.trim(ville) + ", " + jQuery.trim(pays);
}
//...
</script>
Thanks you a lot AlexWien

Resources