lundi 21 septembre 2015

If-statement not working Javascript

Okay, so here is my code.

.ajax({
        type:"POST",
        url: "data.php",
        data:{
            number:number, sprint_count:sprint_count
        },
        dataType: 'json',
        success: function(data){


            var count = data.length;
            var PlannedSprint = 0;

            for(var i = 0; i<count; i++){
                var Column = data[i].Column;
                if(PlannedSprint !== data[i].PlannedSprint){

                    $("#div"+Column+"_"+Team).append(data[i].PlannedSprint);

                 }  



                var PlannedSprint = data[i].PlannedSprint;
                var Team = data[i].Team;

                var Element = data[i].Element;


                $("#div"+Column+"_"+Team).append(Element);
            }
        }
    });

I want the IF-statement to work as long as the data[i].PlannedSprint isnt the same as PlannedSprint. But for some reason the IF-statement isn't working. Why is it so, what is wrong with the if-statement?

In my mind I think it should work like this:

var PlannedSprint = 0; // Set it to 0
if(PlannedSprint !== data[i].PlannedSprint){ // cause of PlannedSprint being set to 0 before this I believe it should work cause the data[i].PlannedSprint wont be 0.
var PlannedSprint = data[i].PlannedSprint; // And then this will give PlannedSprint a new value for the next loop instead of 0.

But this is not working, can someone explain!

Aucun commentaire:

Enregistrer un commentaire