te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Override both _renderItem and _renderMenu - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Override both _renderItem and _renderMenu - Stack Overflow

programmeradmin0浏览0评论

How can I override _renderItem for only #global-search?

$("#global-search").autoplete({
   //       
})._renderMenu = function(ul, items) {
   var self = this;
   ul.append('<table class="ac-search-table"></table>');
   $.each( items, function( index, item ) {
     self._renderItem( ul.find("table"), item );
   });
});

How can I override _renderItem for only #global-search?

$("#global-search").autoplete({
   //       
})._renderMenu = function(ul, items) {
   var self = this;
   ul.append('<table class="ac-search-table"></table>');
   $.each( items, function( index, item ) {
     self._renderItem( ul.find("table"), item );
   });
});
Share Improve this question edited Dec 28, 2012 at 16:28 el_pup_le asked Dec 28, 2012 at 16:21 el_pup_leel_pup_le 12.2k26 gold badges90 silver badges146 bronze badges 4
  • You wanr to override _renderItem or _renderMenu here? – raina77ow Commented Dec 28, 2012 at 16:31
  • Both, I have it working like so: $.ui.autoplete.prototype._renderMenu = ... and ..._renderItem BUT I have multiple AC's on the page and only want one of them to have their functions overridden. – el_pup_le Commented Dec 28, 2012 at 16:38
  • Then I suppose it's better to follow the approach I've shown in my answer. You can define some generic functionality in your own methods, then override it with instance methods. – raina77ow Commented Dec 28, 2012 at 16:40
  • Please help on the following issue stackoverflow./q/33278419/5176876 – bharath Commented Oct 22, 2015 at 10:10
Add a ment  | 

2 Answers 2

Reset to default 14

Remember that you can address the particular instance of the widget created by jQuery UI factory method (_create) via data:

var widgetInst = $("#global-search").autoplete({}).data('ui-autoplete');

... or, since jQuery UI 1.12, via instance() helper method:

var widgetInst = $("#global-search").autoplete('instance'); 

Thus you're able to override its methods with your own:

widgetInst._renderMenu = function(ul, items) {
  var self = this;
  ul.append('<table class="ac-search-table"></table>');
  $.each( items, function( index, item ) {
    self._renderItem( ul.find("table"), item );
  });
};

You have a couple of options:

  1. You can override the _renderItem function so that it does some object parison internally and either calls the original _renderItem function or executes your custom code.

  2. You can create a new widget that inherits from autoplete and override the functions there.

发布评论

评论列表(0)

  1. 暂无评论