3
我工作的一個社區地圖項目,我堅持!我是knockout.js的新手。我試圖使用數據綁定得到這個錯誤 -Knockout.js -Getting錯誤 - 未捕獲的ReferenceError:無法處理結合「與:功能」
淘汰賽3.4.1.js:72未捕獲的ReferenceError:無法處理結合「與:函數(){返回filteredItems}」
的片段HTML源 -
section class="main">
<form class="search" method="post" action="index.html" >
<input type="text" data-bind="textInput: filter" placeholder="Click here/Type the name of the place">
<ul data-bind="with: filteredItems">
<li><span data-bind="text: title, click: $parent.showInfoWindow"></span></li>
</ul>
</form>
</section>
,這是我的視圖模型 -
function viewModel(markers) {
var self = this;
self.filter = ko.observable(''); // this is for the search box, takes value in it and searches for it in the array
self.items = ko.observableArray(locations); // we have made the array of locations into a ko.observableArray
// attributed to - http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html , filtering through array
self.filteredItems = ko.computed(function() {
var filter = self.filter().toLowerCase();
if (!filter) {
return self.items();
} else {
return ko.utils.arrayFilter(self.items(), function(id) {
return stringStartsWith(id.name.toLowerCase(), self.filter);
});
}
});
var stringStartsWith = function (string, startsWith) {
string = string || "";
if (startsWith.length > string.length)
return false;
return string.substring(0, startsWith.length) === startsWith;
};
// populateInfoWindow(self.filteredItems,)
// this.showInfoWindow = function(place) { // this should show the infowindow if any place on the list is clicked
// google.maps.event.trigger(place.marker, 'click');
// };
}
某些線條評論,因爲我仍然在做這個工作。要看到整個項目 - https://github.com/Krishna-D-Sahoo/frontend-nanodegree-neighborhood-map
什麼'locations'在'self.items = ko.observableArray(地點);'? – gkb
'locations'是一個包含位置名稱和座標(經緯度值)的數組。我給了我的github回購鏈接。 –
不應該這行:'返回stringStartsWith(id.name.toLowerCase(),self.filter);'是'返回stringStartsWith(id.name.toLowerCase(),過濾器);'*(不'self') * – user3297291