0

在java脚本中我得到这个错误

Uncaught ReferenceError: baseUrl is not defined 



window.Configurations = Configurations = {
        baseUrl: 'https://mysite.com/',
        detailsEventCustom: baseUrl + 'DetailsEventCustom?EventId=',
        addEventCustom: baseUrl + 'AddEventCustom',
        listAllEventsCustomForDate: baseUrl + 'ListAllEventsCustomForDate?DateToLookUp=',
        dashboardEventsCustom: baseUrl + 'DashboardEventsCustom',
        listAllTimetableEventsCustom: baseUrl + 'ListAllTimetableEventsCustom',
        updateEventCustom: baseUrl + 'UpdateEventCustom?EventId=',
        deleteEventCustom: baseUrl + 'DeleteEventCustom?EventId='
    };

你能指出我在这里做错了什么吗?

4

2 回答 2

2

当您访问对象时,您不能这样

var baseUrl = 'https://mysite.com/';
window.Configurations = Configurations = {
        baseUrl: baseUrl,
        detailsEventCustom: baseUrl + 'DetailsEventCustom?EventId=',
        addEventCustom: baseUrl + 'AddEventCustom',
        listAllEventsCustomForDate: baseUrl + 'ListAllEventsCustomForDate?DateToLookUp=',
        dashboardEventsCustom: baseUrl + 'DashboardEventsCustom',
        listAllTimetableEventsCustom: baseUrl + 'ListAllTimetableEventsCustom',
        updateEventCustom: baseUrl + 'UpdateEventCustom?EventId=',
        deleteEventCustom: baseUrl + 'DeleteEventCustom?EventId='
    };
于 2013-02-05T07:53:39.750 回答
0

这是一个范围界定问题。您仍在大括号之间构建对象,并且所有值都在分配给对象之前进行计算。当您使用它来分配其他值时,baseUrl 根本不存在。你应该这样做:

var baseUrl = 'https://mysite.com/'
window.Configurations = Configurations = {
    baseUrl: baseUrl,
    detailsEventCustom: baseUrl + 'DetailsEventCustom?EventId=',
    addEventCustom: baseUrl + 'AddEventCustom',
    listAllEventsCustomForDate: baseUrl + 'ListAllEventsCustomForDate?DateToLookUp=',
    dashboardEventsCustom: baseUrl + 'DashboardEventsCustom',
    listAllTimetableEventsCustom: baseUrl + 'ListAllTimetableEventsCustom',
    updateEventCustom: baseUrl + 'UpdateEventCustom?EventId=',
    deleteEventCustom: baseUrl + 'DeleteEventCustom?EventId='
};
于 2013-02-05T07:54:17.633 回答