加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – 如何在多个属性上搜索对象(knockout.js tw

发布时间:2020-12-18 00:05:39 所属栏目:安全 来源:网络整理
导读:我在这一点上:) http://blogs.msdn.com/b/rebond/archive/2012/07/18/knockout-js-binding-for-bootstrap-typeahead-plugin.aspx // Bootstrap.Typeahead binding: presently requires custom version from gist: https://gist.github.com/1866577.// Use li
我在这一点上:)

http://blogs.msdn.com/b/rebond/archive/2012/07/18/knockout-js-binding-for-bootstrap-typeahead-plugin.aspx

// Bootstrap.Typeahead binding: presently requires custom version from gist: https://gist.github.com/1866577.
// Use like so: data-bind="typeahead: { target: selectedNamespace,source: namespaces }"
ko.bindingHandlers.typeahead = {
  init: function(element,valueAccessor) {
  var binding = this;
  var elem = $(element);
  var value = valueAccessor();

  // Setup Bootstrap Typeahead for this element.
  elem.typeahead(
  {
    source: function() { return ko.utils.unwrapObservable(value.source); },onselect: function(val) { value.target(val); }
  });

// Set the value of the target when the field is blurred.
elem.blur(function() { value.target(elem.val()); });
  },update: function(element,valueAccessor) {
var elem = $(element);
var value = valueAccessor();
elem.val(value.target());
  }
 };

我有X类,有4个属性.

我想在其3个属性上搜索X对象数组. (其他财产是id)

任何的想法?

解决方法

在.typeahead调用中,传递一个将查看其他属性的 matcher function:
elem.typeahead({
   source: function() { return ko.utils.unwrapObservable(value.source); },onselect: function(val) { value.target(val); },matcher: function(item) {
      // Check if it matches Foo,Bar,or Baz properties.
      return item.Foo.indexOf(this.query) >= 0 || item.Bar.indexOf(this.query) >= 0 || item.Baz.indexOf(this.query) >= 0;
   }
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读