【发布时间】:2017-06-18 10:45:54
【问题描述】:
我对淘汰赛还很陌生,所以我想弄清楚如何让我的小应用程序正常工作。本质上,我希望谷歌地图在点击时从我的列表中放大到一个地方。谷歌地图部分正在工作。我创建了一个使用淘汰赛 foreach 方法填写的列表。然后,我将项目的值绑定到我的函数,但它一直抛出错误:
"knockout-3.4.2.js:1871 Uncaught ReferenceError: Unable to process binding "foreach: function (){return places }" 消息:无法处理绑定“点击:函数(){return zoomToPlace}” 消息:未定义 zoomToPlace”
这是我这部分的 html:
<div class="scroll" id="myUL">
<ul data-bind="foreach: places">
<li>
<input data-bind="value: title, click: zoomToPlace" type="button" class="btn btn-small btn-link">
</li>
</ul>
</div>
这是我的 js:
function PlacesList() {
var self = this;
self.places = ko.observableArray(locations);
self.title = ko.observable();
self.zoomToPlace = function() {
// Initialize the geocoder.
var geocoder = new google.maps.Geocoder();
// Get the place.
var address = this.title();
// Geocode the address/area entered to get the center. Then, center the map on it and zoom in
geocoder.geocode({
address: address,
componentRestrictions: {
locality: 'North York'
}
}, function(results, status) {
map.setCenter(results[0].geometry.location);
map.setZoom(15);
});
}
}
ko.applyBindings(new PlacesList(), document.getElementById("myUL"));
谢谢,您的意见将不胜感激!
【问题讨论】:
标签: javascript jquery google-maps knockout.js