Implementing Autocomplete as a hideable listview (demo included)

后端 未结 1 1374
耶瑟儿~
耶瑟儿~ 2021-01-16 08:02

The start page of my application will have a search box, and a list of useful links below the searchbox (favorites etc)

When someone types text in the searchbox, I w

相关标签:
1条回答
  • 2021-01-16 08:29

    You could try this: give your message an id or a class so it can be selected (in my example I used the id filterable-message), then create a widget like this:

    (function ($, kendo) {
        var ui = kendo.mobile.ui,
            MobileListView = ui.ListView;
    
        var MobileFilterableList = MobileListView.extend({
            init: function (element, options) {
                var that = this;
                MobileListView.fn.init.call(this, element, options);
    
                this._filterableMessage = $("#filterable-message");
                this.resultsVisible(false); // initially not visible
                $(this._filter.searchInput).on("input keyup", function () {
                    that.resultsVisible($(this).val().trim() !== "");
                })
            },
            resultsVisible: function (value) {
                if (value) {
                    this.element.show();
                    this._filterableMessage.hide();
    
                } else {
                    this.element.hide();
                    this._filterableMessage.show();
                }
            },
            options: {
                name: "MobileFilterableList"
            }
        });
    
        kendo.ui.plugin(MobileFilterableList);
    })(window.jQuery, window.kendo);
    

    (demo)

    You could also change how the view filters the data source instead of showing/hiding the list, but unfortunately the code that handles that (ListViewFilter) is private to the ListView, so it would require more code.

    0 讨论(0)
提交回复
热议问题