【问题标题】:debounce it not work去抖它不起作用
【发布时间】:2016-07-12 04:08:39
【问题描述】:
<script type="text/javascript">

    $(function(){

            var parent_id = {};
            var father_name = [];
            var father_occupation = [];
            var father_tele_no = [];
            var father_handph = [];
            var mother_name = [];
            var mother_occupation = [];
            var mother_tele_no = [];
            var mother_handph = [];
            var email = [];
            var remark = [];
            var throttledRequest = _.debounce(function(query, process){
                $.ajax({
                    url: '<?= base_url("student/jason_parent"); ?>
                        '
                        ,cache: false
                        ,success: function(data){
                        parent_id = {};
                        father_name = [];
                        console.log(data);
                        _.each( data, function(item, ix, list){
                        father_name.push( item.father_name );
                        parent_id[ item.father_name ] = item.parent_id;
                        father_occupation[ item.father_name ] = item.father_occupation;
                        father_tele_no[ item.father_name ] = item.father_tele_no;
                        father_handph[ item.father_name ] = item.father_handph;
                        mother_name[item.father_name] = item.mother_name;
                        mother_occupation[item.father_name] = item.mother_occupation;
                        mother_tele_no[item.father_name] = item.mother_tele_no;
                        mother_handph[item.father_name] = item.mother_mother_handph;
                        email[item.father_name] = item.email;
                        remark[item.father_name] = item.remark;
                        });

                        process( father_name );
                        }
                        });
                        }, 300);

                        $(".typeahead").typeahead({
                        source: function ( query, process ) {

                        throttledRequest( query, process );

                        }
                        , updater: function ( selectedName ) {

                        $( "#id" ).val( parent_id[ selectedName ]);
                        $( "#father_occupation" ).val( father_occupation[ selectedName ]);
                        $( "#father_tele_no" ).val( father_tele_no[ selectedName ]);
                        $( "#father_handph" ).val( father_handph[ selectedName ]);
                        $( "#mother_name" ).val( mother_name[ selectedName ]);
                        $( "#mother_occupation" ).val( mother_occupation[ selectedName ]);
                        $( "#mother_tele_no" ).val( mother_tele_no[ selectedName ]);
                        $( "#mother_handph" ).val( mother_handph[ selectedName ]);
                        $( "#email" ).val( email[ selectedName ]);
                        $( "#remark" ).val( remark[ selectedName ]);
                        return selectedName;
                        }
                        });
                        });
    </script>

它不工作

【问题讨论】:

    标签: typeahead.js typeahead


    【解决方案1】:

    我在 debounce 方面遇到了类似的问题,在我的情况下是不同的,但在这里我认为问题是您没有返回 debounced 函数。

    我认为如果你这样使用它应该可以工作:

    $(".typeahead").typeahead({
        source: function ( query, process ) {
           return throttledRequest( query, process );
          },
      ...
      );
    

    【讨论】:

      猜你喜欢
      • 2013-05-17
      • 1970-01-01
      • 2015-10-19
      • 2014-10-09
      • 2021-10-26
      • 2017-02-20
      • 2020-04-26
      • 1970-01-01
      • 2023-04-08
      相关资源
      最近更新 更多