2012-10-28 17 views
45

Ich erhalte eine Fehlermeldung mit folgendem Typoskript Code:Set window.location mit Typoskript

///<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'); 
     }); 

} 

ich einen unterstrichen rot Fehler für die folgenden bin immer:

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

Die Meldung sagt:

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

Weiß jemand, was das bedeutet?

Antwort

88

window.location ist vom Typ Location während .attr('data-href') liefert einen String, so dass Sie es zu window.location.href zuweisen müssen, die von Zeichenfolge ist zu geben. Für, dass Ihre folgende Zeile ersetzen:

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

für diese:

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

haben Sie den href verpasst:

Standard verwenden window.location.href als window.location technisch ein Objekt enthält:

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

versuchen

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