函数变量未定义错误

时间:2017-07-14 07:56:28

标签: javascript

我在Javascript中调用一个函数并传递一些参数(title,subTitle,text)。我调试并检查了它们的值是否被传递给它,我想在回调方法中使用它们但是它们的值没有在该范围内定义。怎么解决这个问题?

 function geocodeQuery(query, title, subTitle, text) {
        //If search manager is not defined, load the search module.
        if (!searchManager) {
            //Create an instance of the search manager and call the geocodeQuery function again.
            Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
                searchManager = new Microsoft.Maps.Search.SearchManager(map);
                geocodeQuery(query);
            });
        } else {
            var searchRequest = {
                where: query,
                callback: function (r) {
                    //Add the first result to the map and zoom into it.
                    if (r && r.results && r.results.length > 0) {
                        var pin = new Microsoft.Maps.Pushpin(r.results[0].location,
                            {
                                title: title,
                                subTitle: subTitle,
                                text: text
                            });
                        map.entities.push(pin);

                        map.setView({ bounds: r.results[0].bestView });
                    }
                },
                errorCallback: function (e) {
                    //If there is an error, alert the user about it.
                    alert("No results found.");
                }
            };

            //Make the geocode request.
            searchManager.geocode(searchRequest);
        }
    }

0 个答案:

没有答案