2

问题:有没有人有使用鞋子的“输入时过滤”下拉控件的示例?

示例:如果您正在寻找我所说的示例,请参阅这些。

4

2 回答 2

2

我从没在野外见过。这是我在分心之前开始工作的代码。它非常粗糙,但也许你可以从这里拿走它:

class Dropdown < Widget
  def initialize (list, opts = {})
    @max_items = opts[:max_items] || 5
    @min_letters = opts[:min_letters] || 3
    @width = opts[:width] || 280
    @fill = opts[:background] || white
    @highlight = opts[:highlight] || yellow
    @match_anywhere = opts[:match_anywhere].nil? ? true : opts[:match_anywhere]
    @ignore_case = opts[:ignore_case].nil? ? true : opts[:ignore_case]
    @entries = list
      @text_box = edit_line :width => @width do |box|
        if box.text.length >= @min_letters
          update_list(box.text)
        else
          @list.clear if @list
          @list = nil
        end
      end
  end

  def update_list(search)
    search.downcase! if @ignore_case
    choices = []
    @entries.collect do |x|
      temp = @ignore_case ? x.downcase : x
      if @match_anywhere
        choices << x if temp.include?(search)
      else 
        choices << x if temp.index(search) == 0
      end
      break if choices.length == @max_items
    end
    @list.clear if @list
    @list = nil
    app.append do
      @list = stack :width => @width do 
        background @fill
        choices.each do |choice| 
          f = flow { para choice }
          f.click do 
            @text_box.text = choice
            @list.clear if @list
            @list = nil
          end
          f.hover {|h| h.contents.first.fill = @highlight }
          f.leave {|l| l.contents.first.fill = nil }
        end
      end
    end unless choices.nil?
    @list.move(0,0)
    @list.displace(0, @text_box.height + @text_box.top)
  end

end

Shoes.app(:width => 500, :height => 500) do
  dropdown ['Breed', 'Green', 'Greetings', 'Phoning', 'Ponies', 'Reed', 'Trees'], {:max_items => 3}
  para 'Ponies are awesome!'
  para 'Bananas are yellow.'
  para 'Sometimes I like to eat bananas, but never ponies.'
end
于 2009-07-04T22:58:51.023 回答
1

尝试基于实际选择框并在选项文本中间匹配的“jquery 选项过滤器”:http: //plugins.jquery.com/project/jquery_options_filter

为自我主义

于 2009-09-14T06:41:08.597 回答