Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

andrea cerqueira

jquery week calendar

Recommended Posts

como eu crio uma função dentro de um evento?

no caso o evento de edição.

já tendei de várias formas...

eventClick : function(calEvent, $event) {
   // retorna SyntaxError: function statement requires a name
   mudaStatus : function(id, status) {
               var newStatus;
               var newStatusTxt;
               if (status == 0) {
                   newStatus = 1;
                   newStatusTxt = 'status';
               } else if (status == 1) {
                   newStatus = 0;
                   newStatusTxt = 'faltou';
               }
               $('.id_pupil_' + id).attr('rel', newStatus);
               $('#status_pupil_' + id).attr('class', 'status_' + newStatus);
               $('#status_pupil_' + id).html(newStatusTxt);
           }
      // ou assim retorna mudaStatus is not defined
      function mudaStatus (id, status) {
               var newStatus;
               var newStatusTxt;
               if (status == 0) {
                   newStatus = 1;
                   newStatusTxt = 'status';
               } else if (status == 1) {
                   newStatus = 0;
                   newStatusTxt = 'faltou';
               }
               $('.id_pupil_' + id).attr('rel', newStatus);
               $('#status_pupil_' + id).attr('class', 'status_' + newStatus);
               $('#status_pupil_' + id).html(newStatusTxt);
           }

}

tudo que tentei retorna undefined, esse último retorna outro erro, erro.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

ou andrea.. não entendi pq você acha que precisa criar a função.

 

o "evento", é um callback, e ele por si só já é uma função.

basta escrever teu código, diretamente:

 

eventClick : function(calEvent, $event) {

               var newStatus;
               var newStatusTxt;
               if (status == 0) {

 

 

ou então, bem looooonge do código do plugin criar a função, e só chamar ela dentro do evento.

Compartilhar este post


Link para o post
Compartilhar em outros sites

então Bruno, eu não dei muito detalhe sobre o problema.

já tentei colocar ela f*** do evento e continuou como not defined.

dentro do envento eu tenho um loop que monta uns links, e essa function eu quero acessar ao clicar nesses link.

meu each tá assim:

$.each(calEvent.pupil_id, function(index, events) {
               newNames = '<div class="name_pupil_' + events.id + '">';
               newNames += events.name;
               if (events.missed == 0) {
                   newNames += '<a href="#" class="status_0 status" onclick="mudaStatus(' + events.id + ',' + events.missed + ');" id="status_pupil_' + events.id + '">faltou</a>';
               } else if (events.missed == 1) {
                   newNames += '<a href="#" class="status_1 status" onclick="mudaStatus(' + events.id + ',' + events.missed + ');" id="status_pupil_' + events.id + '">status</a>';
               }
               newNames += '</div>';
               $('#pupil_names').append(newNames);
           });

acho que agora melhorou né? :)

Compartilhar este post


Link para o post
Compartilhar em outros sites

tipo.. isso aqui tá bem errado:

 

class="status_0 status" onclick="mudaStatus(' + 

 

não faça isso não...

 

 

vá bem longe do código do plugin e declare:

 

$('.status_0status').live('click',function(){
   //rotina aqui
});

não fique amontoando códigos...

Compartilhar este post


Link para o post
Compartilhar em outros sites

tá um pouco dificil de entender a situação, você só tá colocando trechos desconexos..

 

mas vou tentar:

 

newNames += '<a href="#" class="status_0 status" title="'+events.id+'" id="status_pupil_' + events.id + '">faltou</a>';

e ai na função, você resgataria:

 

 

$('.status_0status').live('click',function(){
   alert( $( this ).attr('title') );
});

algo desse tipo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.