dph6308 2015-09-23 19:34
浏览 64

搜索/过滤数组

I have a question. On my site (Concrete 5 based) I have a block to display a list of icons. I have this array. (The array has many more icons than what I've shown, this is just for an example.)

    <?php  $options = array(
    'icon-adjust' => 'Icon Adjust',
    'icon-adjustments' => 'Icon Adjustments',
    'icon-adn' => 'Icon Adn',
    'icon-alarmclock' => 'Icon Alarmclock',
    'icon-align-center' => 'Icon Align-center',
    'icon-align-justify' => 'Icon Align-justify',
    'icon-align-left' => 'Icon Align-left',
    'icon-align-right' => 'Icon Align-right',
    'icon-ambulance' => 'Icon Ambulance',
    'icon-anchor' => 'Icon Anchor',
    'icon-anchor2' => 'Icon Anchor2',
);
?>

I want to modify my search box so a user can type in something to filter out results from in the array. (Example: if they search for anchor, they'd see the two icon-anchor fields).

Can anyone help me out with how to go about this?

Here is my code for future reference:

    <script>
$('input[name=fromPages]').select2({
    placeholder: "<?=t('Search for a Page')?>",
    minimumInputLength: 1,
    width: '100%',
    multiple: true,
    ajax: {
        url: "<?=$view->action('load_pages')?>",
        dataType: 'json',
        quietMillis: 250,
        data: function (term, page) {
            return {
                q: term
            };
        },
        results: function (data, page) { // parse the results into the format expected by Select2.
            var results = [];
            $.each(data, function(i, concretePage) {
                results.push({'id': concretePage.id, 'text': concretePage.name});
            });
            return {
                results: results
            };
        },
        cache: true
    }
});
</script>

And for the select box:

<div class="form-group">
    <?php echo $form->label('fromPages', 'Search for an Icon')?>
    <div>
        <?php echo $form->hidden('fromPages'); ?>
    </div>
</div>

and a picture: (the top search box would filter results from the opened list) http://i.imgur.com/Ksrb7iQ.png?1

  • 写回答

1条回答 默认 最新

  • dongsaohu6429 2015-09-23 19:40
    关注

    Check out typeahead.js library, you're not going to be able to accomplish this with just php

    https://twitter.github.io/typeahead.js/

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?