Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497

    Javascript et array sorting

    Ciao a tutti ero gia' abbastanza avezzo alle follie del motore js di ie ma questa poi e' pua follia.

    sto testanto le funzioni di sorting con array strutturati .. e nel momento un cui devo ordinare un array in maniera decrescente in base ad un campo di un oggetto messo in un array ... beh IE ne fa delle belle.

    VI posto il codice di test, potete tranquillamente copiarlo ed incollarelo in una pagina .html e avviare la pagina c'e' solo del codice html e lo script di test.

    Avviatelo su ff, chomre safari etc... e poi su ie9 ... ne vedrete delle belle

    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
    <
    html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">

    <
    head>
         <
    title>TEST SORTING</title>
        <
    script type="text/javascript">
        
        var 
    B1 null ;
        var 
    B2 null ;
        var 
    B1_STR "" ;
        
        function 
    init()
        {
            
    B1 document.getElementById"execution" ) ;    
            
    B2 document.getElementById"result" ) ;
        }
        
        
        function 
    startTest()
        {
            var 
    a1 = [
                { 
    id:},
                { 
    id:},
                { 
    id:},
                { 
    id:},
                { 
    id:},
                { 
    id:},
            ]
        
            
    B1_STR "<pre>START SORTING\n-----------------------------\n" ;
            var 
    a2 a1.sortsorter )
            
    B1_STR +="\n-----------------------------\nEND SORTING</pre>" ;
            var 
    str "<pre>" ;
            for( var 
    i=i<a2.length i++ )
            {
                
    str += "["+i+"] => "+a2[i].id+"\n" ;
            }
            
    str += "</pre>" ;
            
            
    B1.innerHTML B1_STR ;
            
    B2.innerHTML str ;
            
        }
        
        function 
    sortera,)
        {
            
    B1_STR +=" ["+a.id+"] < ["+b.id+"] \n" ;
            return 
    a.id<b.id ;
        }
        
        
        
        
        
    </script>

    </head>
    <body onload="init()">
        [url="javascript:startTest()"]START TEST !!!!! [/url]
        <table width="500">
        <tr>
            <td width="50%">EXECUTION</td>
            <td width="50%">RESULT</td>
        </tr>
            
        <tr>
            <td valign="top"><div id="execution"></div></td>
            <td valign="top"><div id="result"></div></td>
        </tr>
        </table>
    </body></html> 
    Avete idea di come farlo aprtire sotto ie ? A meno di non dover identificare il browser et invertire i controlli ?

    Grassie.

  2. #2
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    Up

    Nessuno ????????

  3. #3
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    UP PLS QUALCUNO!!!!!!!! sto

    non dovro mica fare riconoscmento browser per aver un sorting corretto tra ie e i w3c ? ...

    HEEEEEEEEEEEEEEEEEEEEEEELP !!!


  4. #4
    Hai provato a farlo come va effettivamente fatto? La funzione sorter dovrebbe tornare un intero...

    prova:

    codice:
    function sorter( a,b ) 
    { 
       return a.id - b.id ; 
    }
    max

    Silence is better than bullshit.
    @mmarcon
    jHERE, Maps made easy

  5. #5
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    OMG ....... che pollo !!!!!

    cacchio vero c'era scritto pure nelle API .....

    PWNED LIKE A CHICKEN !!!!

    ghghghghgh grazzie ora fuge posto lo script corretto :

    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
    <
    html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">

    <
    head>
         <
    title>TEST SORTING</title>
        <
    script type="text/javascript">
        
        var 
    B1 null ;
        var 
    B2 null ;
        var 
    B1_STR "" ;
        
        function 
    init()
        {
            
    B1 document.getElementById"execution" ) ;    
            
    B2 document.getElementById"result" ) ;
        }
        
        
        function 
    startTest()
        {
            var 
    a1 = [
                { 
    id:},
                { 
    id:},
                { 
    id:},
                { 
    id:},
                { 
    id:},
                { 
    id:},
            ]
        
            
    B1_STR "<pre>START SORTING\n-----------------------------\n" ;
            var 
    a2 a1.sortsorter )
            
    B1_STR +="\n-----------------------------\nEND SORTING</pre>" ;
            var 
    str "<pre>" ;
            for( var 
    i=i<a2.length i++ )
            {
                
    str += "["+i+"] => "+a2[i].id+"\n" ;
            }
            
    str += "</pre>" ;
            
            
    B1.innerHTML B1_STR ;
            
    B2.innerHTML str ;
            
        }
        
        function 
    sortera,)
        {
            
    B1_STR +=" ["+a.id+"] < ["+b.id+"] \n" ;
            
            return 
    a.id-b.id ;
        }
        
        
        
        
        
    </script>

    </head>
    <body onload="init()">
        [url="javascript:startTest()"]START TEST !!!!! [/url]
        <table width="500">
        <tr>
            <td width="50%">EXECUTION</td>
            <td width="50%">RESULT</td>
        </tr>
            
        <tr>
            <td valign="top"><div id="execution"></div></td>
            <td valign="top"><div id="result"></div></td>
        </tr>
        </table>
    </body></html> 
    Attenzione il forum mi onverte START TEST !!!!!

    in START TEST !!!!!

    Se volete testare togliete il "-" dalla chiamata js Ma ma ma ma perche' nn posso scrivere javascript tutto attaccato ??? mah sara per evitare injections

    Cmq fate attenzione quando usate il codice a quella chiamata.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.