2

Stackoverflow コミュニティの皆様、こんにちは。

次の問題があり、自分で処理できません。

次の検索フォームがあります。

    <li class="list-group-item active" data-ignore-list-search="ignore"><?php echo $translate->_('Animals'); ?><span class="icon-search pull-right" rel="SearchBox" data-placement="bottom" data-container="body"></span>

        <div id="popover_content_wrapper" class="hide">
        <input placeholder="<?php echo $translate->_('Search'); ?> " id="FilterForm" class="filterform filterinput" type="text">
        </div>
    </li>

そして、次のjQueryコードを使用してulアイテムをフィルタリングしています:

(function(jQuery){
var ListSearch = function() {};
ListSearch.prototype = {
    /**
     * run
     * start incremental search.
     * @param {} input
     * @param {} target
     * @returns {} 
     */
    run: function(input, target){
        var _this = this;
        var tagName = target.get(0).tagName;

        input.on('keyup', function(e){
            text = _this.getInputText(input);

            switch(tagName){
            case 'TABLE':
                _this.listSearchTable(target, text);
                break;
            case 'UL':
                _this.listSearchListUl(target, text);
                break;
            case 'OL':
                _this.listSearchListOl(target, text);
                break;
            case 'DL':
                _this.listSearchListDl(target, text);
                break;
            default:
                throw new Error('Illegal tag name ' + targetObject.targetTagName);
            }
        });
    },

    getInputText: function(input){
        return input.val();
    },

    /**
     * tag table
     */
    listSearchTable: function(target, text){
        this.listSearchCommon('tr', target, text);
    },

    /**
     * tag ul
     */
    listSearchListUl: function(target, text){
        this.listSearchCommon('li', target, text);
    },

    /**
     * tag ol
     */
    listSearchListOl: function(target, text){
        return this.listSearchListUl(target, text);
    },

    /**
     * tag dl
     */
    listSearchListDl: function(target, text){
        this.listSearchCommon('dd dt', target, text);
    },

    /**
     * commondSearchList
     */
    listSearchCommon: function(tagName ,target, text){
        var _this = this;
        var searchWords = this.searchWordToWords(text);
        var wordLength = searchWords.length;

        target.find(tagName).each(function(){
            var thisJQuery = jQuery(this);
            if (thisJQuery.data('ignore-list-search') === 'ignore') return true;

            var body = _this.getBody(thisJQuery);
            var displayFlag = true;

            var wordCount = 0;
            for(wordCount = 0; wordCount < wordLength; wordCount++){
                var word = searchWords[wordCount];

                var pattern = new RegExp(word, 'i');
                if ( !body.match(pattern) ) {
                    displayFlag = false;
                    break;
                }
            }

            jQuery(this).css('display', _this.getDisplayProperty(tagName, displayFlag));
            return true;
        })
    },

    /**
     * getDisplayProperty
     * @param {} tagName
     * @param {} flag
     * @returns {} 
     */
    getDisplayProperty: function(tagName, flag){
        switch(tagName){
        case 'tr':
            return flag?'table-row':'none';
        case 'li':
            return flag?'block':'none';
        case 'dd dt':
            return flag?'list-item':'none';
        default:
            throw new Error('Illegal tag name ' + targetObject.targetTagName);
        }
    },

    /**
     * getBody
     * @returns {}
     */
    getBody: function(target){
        var body = target.text();
        return jQuery.trim(body);
    },

    /**
     * searchWordToWords
     * a search text split to search words.
     * @param {} body
     * @param {} searchWord
     * @returns {} 
     */
    searchWordToWords: function(text){
        text = jQuery.trim(text);
        var pattern = new RegExp(/[  \-\/]/);
        var words = text.split(pattern);

        // delete empty element
        var newWords = new Array();
        var wordsLength = words.length;
        var wordsCount = 0;
        for (wordsCount = 0; wordsCount < wordsLength; wordsCount++){
            var word = words[wordsCount];
            if (word != ""){
                newWords.push(words[wordsCount]);
            }
        }
        return newWords;
    }
}

/**
 * Main stream
 */
jQuery.fn.listSearch = function(input, options){
    var options = jQuery.extend(jQuery.fn.listSearch.defaults, options);

    // set using objects.
    var target = jQuery(this);
    switch (jQuery.type(input)){
        case 'string':
            input = jQuery(input);
            break;
        case 'object':
            input = input;
            break;
        default:
            throw 'Argiment value "' + input + '" is invalid.';
    }

    // Event start
    listSearch = new ListSearch();
    listSearch.run(input, target);

    return target;
};

/**
 * default settings.
 */
jQuery.fn.listSearch.defaults = {

};

    $('#AnimalList').listSearch('#FilterForm')

;

})(jQuery);

これは正常に動作します..しかし、#FilterForm 入力をポップオーバーに入れると、uls が除外されなくなります。

私のポップオーバーjQueryコード:

$('[rel=SearchBox]').popover({ 
    html : true, 
    content: function() {
      return $('#popover_content_wrapper').html();
    },
    trigger: 'click'
});

私のULには特別なタグなどはありません。

前もって感謝し、私の変な英語で申し訳ありません [編集 - 修正済み]: 私はドイツ出身です。

こんにちは、ダニエル

4

1 に答える 1

-1

@ user2908086、同じ「filterform」テキストを同じ入力フィールドで異なるタイプで2回使用しているためです! 使用するものは次のとおりです: id="FilterForm" + class="filterform" ! CSS で「filterform」クラス テキストを見つけ、「filterform」の名前を変更し、ID と同じでないことを確認します。次に、入力に同じクラス名を追加して、それが機能するかどうかを確認してください! 幸運を!

于 2013-10-22T18:08:18.313 に答える