2012-10-28 27 views
45

sto ottenendo un errore con il seguente codice dattiloscritto:Set window.location con dattiloscritto

///<reference path='../../../Shared/typescript/jquery.d.ts' /> 
///<reference path='../../../Shared/typescript/jqueryStatic.d.ts' /> 

function accessControls(action: Action) { 
    $('#logoutLink') 
     .click(function() { 
      var $link = $(this); 
      window.location = $link.attr('data-href'); 
     }); 

} 

sto ottenendo un errore rosso sottolineato quanto segue:

$link.attr('data-href'); 

Il messaggio dice:

Cannot convert 'string' to 'Location': Type 'String' is missing property 'reload' from type 'Location' 

Qualcuno sa cosa significa?

risposta

88

window.location è di tipo Location mentre .attr('data-href') restituisce una stringa, quindi bisogna assegnarlo a window.location.href che è di tipo stringa troppo. Per questo sostituire il vostro seguente riga:

window.location = $link.attr('data-href'); 

per questo uno:

window.location.href = $link.attr('data-href'); 
11

avete perso la href:

standard, Per utilizzare window.location.href come window.location è tecnicamente un oggetto contenente:

Properties 
hash 
host 
hostname 
href <--- you need this 
pathname (relative to the host) 
port 
protocol 
search 

provare

window.location.href = $link.attr('data-href'); 
Problemi correlati