2

I'm putting together a tournament bracket system allowing you to drag 'winners' to the next round, and if applicable the loser is automatically transfered to his place in a losers bracket. After each drop I'm sending to php details about the match for both individual tracking purposes as well as refilling the positions in the event it is shut down and reopened.

I ran into a problem where I was sending some unwanted characters that I used .replace() to rid myself and now everything on the winners side works fine, but anything on the losers side doesn't. Hoping someone can help me figure out the cause of this.

15:   $(window).load(function(){
16:     $(".make-draggable, .draggable, .drag").draggable({
17:         helper: "clone",
18:         snap: ".draggable",
19:         snapMode: "inner"
20:     });
21:     $(".draggable").droppable({
22:         drop: function(event, ui) {
23:             var elemText = ui.draggable.text();
24:             $(this).html(elemText);
25:             var outB = ui.draggable.attr('id').split("-");
26:             var pl1;
27:             var pl2;
28:             if (outB[0] == "go") {
29:                 var num = outB.length;
30:                 var loser;
31:                 var loserval;
32:                 var losloc;
33:                 var losid = outB[1];
34:                 var numchars = outB[1].length;
35:                 if (num === 2) {
36:                     var i = 1;
37:                     loser = (losid.charAt(0) + "-");
38:                     pl1 = elemText;
39:                    for (i = 1; i < numchars; i++) {
40:                         loser = (loser+losid.charAt(i));
41:                     }
42:                     loserval = $("#go-" + loser);
43:                     losloc = ("#"+losid);
44:                     $(losloc).html(loserval.text());
45:                     pl2 = loserval.text();
46:                 } else if (num === 3) {
47:                     loser = (outB[1] + outB[2]);
48:                     loserval = $("#go-" + loser);
49:                     losloc = ("#"+loser);
50:                     $(losloc).html(loserval.text());
51:                     pl1 = loserval.text();
52:                     pl2 = elemText;
53:                 }
54:             } else {
55:               var getround = $(this).attr('id');
56:       if(getround == 'winner') {
57:           pl1 = $('#winnerb').text();
58:            pl2 = $('#loserb').text();
59:          } else {
60:            var inti = ui.draggable.attr('id').substring(1);
61:            if (inti%2 == 0) {
62:               var apl =  inti - 1;
63:               pl1 = elemText;
64:              pl2 = $('#l'+apl).text();
65:               alert(apl);
66:            } else {
67:               var apl =  inti++;
68:               alert(apl);
69:              pl1 = $('#l'+apl).text();
70:              pl2 = elemText;
71:            }
72:          }
73:             }
74:             var matrou = ui.draggable.parent().attr("id").split("-");
75:             $.urlParam = function(name){
76:                 var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
77:             return results[1] || 0;
78:             }
79:             pl1 = pl1.replace(/(\r\n|\n|\r)/gm,"");
80:             pl2 = pl2.replace(/(\r\n|\n|\r)/gm,"");
81:             elemText = elemText.replace(/(\r\n|\n|\r)/gm,"");
82:             var params = 'win='+elemText+'&p1='+pl1+'&p2='+pl2+'&match='+matrou[3]+'&round='+matrou[1]+'&wloc='+$(this).parent().attr('id')+'-'+$(this).attr('id')+'&lloc='+$(losloc).parent().attr('id')+'-'+$(loserval).attr('id')+'&tid='+$.urlParam('tid');
83:             xmlhttp=new XMLHttpRequest();
84:             xmlhttp.onreadystatechange=function() {
85:                 if (xmlhttp.readyState==4 && xmlhttp.status==200) {
86:                 }
87:             }
88:             xmlhttp.open("POST","sub_match.php",true);
89:             xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
90:             xmlhttp.setRequestHeader("Content-length", params.length);
91:             xmlhttp.setRequestHeader("Connection", "close");
92:             xmlhttp.send(params);            
93:         }
94:     });
95:   });

Metro (XAML/C#): detect installation and/or first run

When creating Metro applications in XAML/C#, how do I detect when the application is first installed or run for the first time since installation (or potentially upgrade)? I need to use this opportunity to ensure that my database schema is correct and potentially synchronise some base data.

I had hoped that I could pick this up from the LaunchActivatedEventArgs within the OnLaunched method, but there does not seem to be a valid value for the Kind or PreviousExecutionState that I can use.

Thanks.

4

2 に答える 2

1

私は携帯電話を使用しているため、コードをデバッグするのは少し難しいですが、62 行目と 66 行目では、要素のテキストを取得するのではなく、要素を取得して p1 に割り当てるだけであることに気付きました。その行の最後に .text() を追加してみてください。

于 2012-06-03T16:14:05.543 に答える
0

並んでいると思います62

  pl1 = $('l'+(inti+1));

する必要があります

  pl1 = $('l'+(inti+1)).text();

そして並んで66

pl2 = $('l'+(inti+1));

する必要があります

pl2 = $('l'+(inti+1)).text();
于 2012-06-03T17:04:22.360 に答える