다음 TypeScript 코드에서 오류가 발생합니다.
///<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');
});
}
다음에 대해 밑줄이 그어진 빨간색 오류가 발생합니다.
$link.attr('data-href');
메시지 내용 :
Cannot convert 'string' to 'Location': Type 'String' is missing property 'reload' from type 'Location'
이것이 무엇을 의미하는지 아는 사람이 있습니까?
답변
window.location
is of type Location
while .attr('data-href')
returns a string, so you must assign it to window.location.href
which is of string type. 이를 위해 다음 줄을 바꿉니다.
window.location = $link.attr('data-href');
이것에 대해 :
window.location.href = $link.attr('data-href');
답변
당신은 href
:
표준, 기술적으로 다음을 포함하는 객체 window.location.href
로 사용하려면window.location
Properties
hash
host
hostname
href <--- you need this
pathname (relative to the host)
port
protocol
search
시험
window.location.href = $link.attr('data-href');