5

私はこの時点です:)

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());
  }
 };

4つのプロパティを持つXクラスがあります。

Xオブジェクト配列の3つのプロパティを検索したいと思います。(その他のプロパティはidです)

何か案が?

4

1 に答える 1

4

.typeahead 呼び出しで、他のプロパティを調べるマッチャー関数を渡します。

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;
   }
});
于 2012-12-03T19:42:14.307 に答える