Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Intreccio con Prototype.js

    Dovrei fare qualcosa del tipo

    nel file primo.js

    codice:
    function startSystemMenu(){
    	
    	// Crea un'instanza della classe SystemMenu
    	new Ajax.Request(SYSTEM_MENU_PAGE,
    		{
    			method: 'get',
    			asynchronous: false,
    			contentType: 'text/xml',
    			onSuccess: function(transport){
    				systemMenu = new SystemMenu(
    						transport.responseXML,
    						NUM_LATERAL_BUTTONS,
    						NUM_COULOUMNS);
    			},
    			onFailure: function(){
    				alert("Status: " + ajax.status);
    				alert("Errore: " + ajax.statusText);
    			}
    		});
    
    	........
    	
    	// Fa un 'update' del menu presentando il primo livello
    	systemMenu.update('1', 1);
    	
    	........

    nel file SystemMenu.js
    codice:
    var SystemMenu = Class.create({
    	
    	initialize: function(xmlRef, numLateralButtons, coloumns){
    		
    		.......
    
    	},
    
    
    	update: function(parentIdNode, page){
    	
    		.......
    
    		this.riferimentoAdUnElementoIMG.onclick = function(){
    			SystemMenu.stampaId(param);
    		};
    	
    
    	},
    
    
    	stampaId: function(clickedNode){
    		alert(clickedNode.getAttribute('id'));
    	},
    
    
    });
    Ovviamente la cosa non funziona, altrimenti non sarei qui, l'errore che ottengo è SystemMenu.stampaId is not a function. Prima di scrivere SystemMenu.stampaId(param) avevo provato con this.stampaId(param) ma ovviamente al momento del click il this è rappresentato dall'immagine su cui si è cliccato.

    Come ne esco? Grazie.

    Lorenzo

  2. #2
    Frontend samurai L'avatar di fcaldera
    Registrato dal
    Feb 2003
    Messaggi
    12,924
    codice:
    update: function(parentIdNode, page){
    	
                    var _self = this;
    		this.riferimentoAdUnElementoIMG.onclick = function(){
    			_self.stampaId(param);
    		};
    	
    
    	},
    non conosco bene prototype: potrebbe esserci una soluzione migliore
    Vuoi aiutare la riforestazione responsabile?

    Iscriviti a Ecologi e inizia a rimuovere la tua impronta ecologica (30 alberi extra usando il referral)

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.