Bonjour à tous,
Voilà, je suis un débutant en JS, et j'aurai besoin d'éclaircissement concernant mon problème car après avoir lu pleins de choses sur le Web, je suis un peu perdu.
En fait, j'aimerai prendre en compte les cases qui peuvent être sélectionnées par l'utilisateur final de l'application. Je vous met le visuel de l'appli telle qu'elle est actuellement. Je vous mets aussi mon code JS qui permet de produire un fichier XML en fonction des lignes affichées.
MON BUT ? ---> Ce que je souhaite, c'est produire le même résultat mais au lieu de prendre en compte les lignes ($(selector) .find("tr").each( .......)), c'est prendre en compte les cases qui vont être cochées.
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <tr> <td class="area">${b.area}</td> <td class="position">${b.position}</td> <td class="elecroute">${b.elecroute}</td> <!-- <td><input type="checkbox" name="BS1" id="BS1" /> <!--<label for="BS1"></label> --> <td class="bsolution1">${b.bsolution1}</td> <td><input type="checkbox" name="BS1" id="BS1" /> <label for="BS1"></label> </td> <td><img src="image/${b.bsolution1}" width="220px" height="140px"/></td> <!-- 160/100 - Initialement : width="220px" height="140px / b.bsolution1, b.img1 ne fonctionne pas --> <td class="bsolution2">${b.bsolution2}</td> <td><input type="checkbox" name="BS2" id="BS2" /> <label for="BS2"></label> </td> <td><img src="image/${b.bsolution2}" width="220px" height="140px"/></td> <td class="bsolution3">${b.bsolution3}</td> <td><input type="checkbox" name="BS3" id="BS3" /> <label for="BS3"></label> </td> <td><img src="image/${b.bsolution3}" width="220px" height="140px"/></td> <td class="bsolution4">${b.bsolution4}</td> <td><input type="checkbox" name="BS4" id="BS4" /> <label for="BS4"></label> </td> <td><img src="image/${b.bsolution4}" width="220px" height="140px"/></td> <td class="bsolution5">${b.bsolution5}</td> <td><input type="checkbox" name="BS5" id="BS5" /> <label for="BS5"></label> </td> <td><img src="image/${b.bsolution5}" width="220px" height="140px"/></td>
CODE JS :
Comment puis-je mettre en place pour que ca fonctionne ? Je pense peut-être que le changement peut s'opérer au niveau de la ligne 20 : $(selector) .find("tr").each
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 <script type="text/javascript"> function encodeAndEscapeXML(string) { if ($.trim(string) != "") { /*string = string.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");*/ string = string.replace(/&(?!(amp;)|(lt;)|(gt;)|(quot;)|(#39;)|(apos;))/g, "&"); string = string.replace(/([^\\])((\\\\)*)\\(?![\\/{])/g, "$1\\\\$2"); //replaces odd backslash(\\) with even. } else { string = ""; } return string; } function tableToXML(selector) { var indent=" "; var backslah="\n"; var xml = "<airbus>" + "\n"; var bracket_id=0; $(selector) .find("tr").each( function() { xml += "\n<Bracket id=" + '"' + bracket_id++ + '"' + " >"; $(this).find("td.area").each( function() { xml+= backslah + indent + "<area name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />"; }); $(this).find("td.position").each( function(){ xml+= backslah + indent + "<position name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />"; }); $(this).find("td.elecroute").each( function(){ xml+= backslah + indent + "<elecroute name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />"; }); /* bracketSolution1 */ $(this).find("td.bsolution1").each( function(){ xml+= backslah + indent + "<bracketSolution1 name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " >"; }); $(this).find("td.bsolution1").each( function(){ xml+= backslah + indent + indent + "<picture path=" + '"' + encodeAndEscapeXML($(this).html()) + ".png" + '"' + " />"; }); $(this).find("td.bsolution1").each( function(){ if( $(this).html().startsWith("E",0)) { xml+= backslah + indent + indent + "<partsRef1BS1 name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />"; } else { $(this).remove(); } });
J'ai essayé ça mais en vain : $(selector) .find("tr").each.checked=true
En fait, j'aimerai récupérer la valeur de la colonne juste avant (E039-5 par exemple) pour le 1er check, et ainsi de suite ...
Partager