不能调用未定义的 GetJson 的方法“toLowerCase”
Cannot call method 'toLowerCase' of undefined GetJson
我陷入了在为
我的谷歌地图v3获取Jsonresult时需要修复代码的情况,但是当我在循环中从jquery加载我的地图时,此错误显示我不知道如何解决这个问题Uncaught TypeError: Cannot call method 'toLowerCase' of undefined
我没有看到一些有这个问题的装置。我希望有人可以帮助我解决这个问题
这是我的Javascript代码:
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
var minZoomLevel = 4;
var zooms = 7;
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('map'), {
zoom: minZoomLevel,
center: new google.maps.LatLng(38.50, -90.50),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Bounds for North America
var strictBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(15.70, -160.50),
new google.maps.LatLng(68.85, -55.90)
);
// Listen for the dragend event
google.maps.event.addListener(map, 'dragend', function () {
if (strictBounds.contains(map.getCenter())) return;
// We're out of bounds - Move the map back within the bounds
var c = map.getCenter(),
x = c.lng(),
y = c.lat(),
maxX = strictBounds.getNorthEast().lng(),
maxY = strictBounds.getNorthEast().lat(),
minX = strictBounds.getSouthWest().lng(),
minY = strictBounds.getSouthWest().lat();
if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;
map.setCenter(new google.maps.LatLng(y, x));
});
// Limit the zoom level
google.maps.event.addListener(map, 'zoom_changed', function () {
if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
});
}
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
function codeAddress() {
$.getJSON("/Dashboard/LoadWorkerList", function (address) {
var infowindow = new google.maps.InfoWindow();
$.each(address,function (index,currVal) {
currVal = $(this).val();
geocoder.geocode({ 'address': currVal }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
icon: iconBase + 'man.png',
position: results[0].geometry.location,
title: currVal
})
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(currVal);
infowindow.open(map, marker);
}
})(marker, currVal));
address.push(marker);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
});
return true;
}
window.onload = function () {
initialize();
codeAddress();
}
</script>
这是 LoadWorkerList 的代码
public JsonResult LoadWorkerList()
{
var workerList = new List<Worker_Address>();
// check if search string has value
// retrieve list of workers filtered by search criteria
var list = (from a in db.Worker_Address
where a.LogicalDelete == false
select a).ToList();
List<WorkerAddressInfo> wlist = new List<WorkerAddressInfo>();
foreach (var row in list)
{
WorkerAddressInfo ci = new WorkerAddressInfo
{
ID = row.ID,
Worker_ID = row.WorkerID,
AddressLine1 = row.Address_Line1 + " " + row.Address_Line2+ " " +row.City + " "+ GetLookupDisplayValById(row.State_LookID),
LogicalDelete = row.LogicalDelete
};
wlist.Add(ci);
}
return Json(wlist.ToList().OrderBy(p => p.AddressLine1), JsonRequestBehavior.AllowGet);
}
错误在此 ff: 代码中
Uncaught TypeError: Cannot call method 'toLowerCase' of undefined
v.fn.extend.val jquery-1.8.3.min.js:2
(anonymous function) $.each(address,function (index,currVal) {
v.extend.each jquery-1.8.3.min.js:2
(anonymous function) currVal = $(this).val();
l jquery-1.8.3.min.js:2
c.fireWith jquery-1.8.3.min.js:2
T jquery-1.8.3.min.js:2
r
好吧,从堆栈跟踪来看,它是这么说的; - $(this).val()
in currVal = $(this).val();
返回的值在某个索引处未定义,或者 - address
at $.each(address,function (index,currVal)
中的某个索引的值未定义。
确保 $.each(address,function (index,currVal) {
中的索引值不超过address
的长度,并且address
中的所有元素都被分配了一个值
我猜您正在尝试对数组address
中的地址进行地理编码,并且它试图使地址成为小写字符串,但没有找到字符串。
如果address
不是数组,则使其成为数组,它不应该是字符串
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 数组在递归方法中设置为null
- 打破承诺链的好方法是什么
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 使用“;这个“;JavaScript原型方法中的关键字
- 序列化数据属性中对象的最可靠方法
- 使用Objective-C的JavaScript注入方法
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 有没有一种方法可以防止img get请求使用css或js发生
- Javascript,有没有一种方法可以将数组写成没有逗号或空格的单个文本字符串
- toBoolean方法类似于toString
- 如何在单击复选框后调用控制器方法
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 递归使用 eval() 是检查程序执行的好方法吗?
- 如何在webView,Android中从@JavascriptInterface方法调用Javascript
- Twitter bootstrap typeahead(未定义的方法'toLowerCase')
- 不能调用未定义的 GetJson 的方法“toLowerCase”
- 未捕获的类型错误:无法调用未定义的方法“toLowerCase”
- 有什么方法来DRY这段代码吗?“+“toLowerCase()