erstellen Sie ein mehrdimensionales array (nXn) - matrix mit javascript

Ich versuche zum erstellen einer matrix-Tabelle. Die Werte werden richtig in der matrix werden die Benutzereingaben aus einem html-Tabelle (im Grunde eine einmalige pairing-Tabelle, die paarweise zwei Elemente zu einer Zeit und für jedes paar kann ein Benutzer wählen, welche er bevorzugt und wie viel es ist bevorzugt auf einer Skala von 1-9 über radio-buttons). es ist die Präferenzen, d.h. 1-9, die eingesteckt in die matrix-Tabelle und die Anzahl der einzigartigen Paarung, die detemines die Länge der matrix.

wenn das matric generiert wird, möchte ich etwas davon haben:

0    1    2    3    4    sum    
1   [1]  [6]  [2]  [8]    17    
2   [ ]  [1]  [9]  [4]    15    
3   [ ]  [ ]  [1]  [7]    8    
4   [ ]  [ ]  [ ]  [1]    1    

Das problem ist jetzt, ich möchte die Werte der angeklickten radios in der matix. Ich weiß, wie um es zu bekommen, wissen aber nicht, wie man es passend in die matrix. Hier ist der code, den ich für jetzt, pls Fragen Sie mich Fragen, wenn nötig, danke:

$(function(){
    var tableLenght = new Array();
    $('#matrix').click(function(){
    var counter = 0;
    $("#riskForm tr").each(function(){
        //ignores the header of the table (the title)
    if(counter >=1){
        tableLenght.push($(this).closest('tr').children("td:eq(1)").text());
    }
    counter++;
    });

//get unique attributes of in our table
var uniqueList = new Array();
//push first element onto list
uniqueList.push(tableLenght[0]); //pushes current elem onto the array
var cur = tableLenght[0]; //sets first element by default
for(var i = 1; i < tableLenght.length; i++){ //loops through the whole lenght of our array
    if(cur != tableLenght[i]){//checks if the current is not same as the next one
            cur = tableLenght[i]; //sets the new elemt
    uniqueList.push(tableLenght[i]); //pushes onto the array
    }
}
alert(uniqueList); //alerts only the unique table rows in the tableLenght array
var myArray = new Array(uniqueList);

    for (var i = 0; i < uniqueList; i++) {
        myArray[i] = new Array(uniqueList);
        for (var j = 0; j < uniqueList; j++) {
            myArray[i][j] = '';
        }
}
});

//to show/get the values of selected radio buttons
function showValues() {
    var fields = $( ":input").serializeArray();
    $( "#results" ).empty();
    jQuery.each( fields, function( i, field ) {
    $( "#results" ).append( field.value + " " );
    });
}

$( ":checkbox, :radio" ).click( showValues );
showValues();
$('#display').click(function (n) {
document.location.href="trialIndex.php"
    });
});

Ihre Hilfe ist sehr geschätzt!

InformationsquelleAutor user3045800 | 2014-01-13
Schreibe einen Kommentar