文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
How to use remoteFilter
Normal Usage
If remoteFilter
is set as a function, At.js will invoke it if local filter can not find any data so, At.js will always invoke remoteFilter
with matched string
and then you can use it to fetch data from server by the matched string
:
$('#inputor').atwho({ at: "@", callbacks: { /* If function is given, At.js will invoke it if local filter can not find any data @param query [String] matched query @param callback [Function] callback to render page. */ remoteFilter: function(query, callback) { $.getJSON("/users.json", {q: query}, function(data) { callback(data.usernames) }); } } });
Caching example
Here is an example how I implement caching with this plugin. Hope its useful for folks here...
var cachequeryMentions = [], itemsMentions, searchmentions = $('textarea').atwho({ at: "@", callbacks: { remoteFilter: function (query, render_view) { var thisVal = query, self = $(this); if( !self.data('active') && thisVal.length >= 2 ){ self.data('active', true); itemsMentions = cachequeryMentions[thisVal] if(typeof itemsMentions == "object"){ render_view(itemsMentions); }else { if (self.xhr) { self.xhr.abort(); } self.xhr = $.getJSON("/getmentions",{ term: thisVal }, function(data) { cachequeryMentions[thisVal] = data render_view(data); }); } self.data('active', false); } } } }); });
Hope it helps!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论