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

前端之家收集整理的这篇文章主要介绍了twitter-bootstrap – 如何在多个属性上搜索对象(knockout.js twitter bootstrap typeahead)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在这一点上:)

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

// 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个属性.@H_404_3@

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

任何的想法?@H_404_3@

解决方法

在.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;
   }
});
原文链接:https://www.f2er.com/bootstrap/447212.html

猜你在找的Bootstrap相关文章