javascript-Knockout.js-获取错误-未捕获ReferenceError:无法处理“ with:function”绑定
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-Knockout.js-获取错误-未捕获ReferenceError:无法处理“ with:function”绑定,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2014字,纯文字阅读大概需要3分钟。
内容图文
![javascript-Knockout.js-获取错误-未捕获ReferenceError:无法处理“ with:function”绑定](/upload/InfoBanner/zyjiaocheng/666/67c77a724b574500b37ed4253eb220e3.jpg)
我正在做一个邻里地图项目,被卡住了!我是基因敲除的新手.我正在尝试使用数据绑定得到此错误-
Knockout-3.4.1.js:72未捕获ReferenceError:无法处理绑定“ with:function(){returnfilteredItems}”
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>
这是我的viewModel-
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
解决方法:
with绑定使用提供的元素创建新的绑定上下文.由于对< span>中的标题的引用而引发该错误.元素,但filteredItems没有标题属性.
如果要显示< li>对于filteredItems数组中每个元素的元素,可以使用foreach绑定,如下所示:
<ul data-bind="foreach: filteredItems">
<li><span data-bind="text: title, click: $parent.showInfoWindow"></span></li>
</ul>
内容总结
以上是互联网集市为您收集整理的javascript-Knockout.js-获取错误-未捕获ReferenceError:无法处理“ with:function”绑定全部内容,希望文章能够帮你解决javascript-Knockout.js-获取错误-未捕获ReferenceError:无法处理“ with:function”绑定所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。