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

you cannot do it like this
when you are accessing the object hasn't been made try doing this instead

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

This is a scoping problem. You are still building the object between the curly braces, and all values are calculated before they are assigned to the object. baseUrl simply doesn't exist yet when you are using it to assign the other values. You should do something like this instead:

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 に答える