- 浏览: 192762 次
- 性别:
文章分类
最新评论
Auto Complete -- Typeahead 和DateRangePicker
一个很好用的AutoComplete js:
https://twitter.github.io/typeahead.js/
这里是自己测试的一些demo:
<script src="jquery-1.11.1.min.js"></script>
<script src="typeahead.bundle.js"></script>
<script src="handlebars-v1.3.0.js"></script>
<p>
1.Basic
</p>
<div id="the-basics">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
<script>
var substringMatcher_basic = function(strs) {
return function findMatches(q, cb) {
var matches, substrRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
// the typeahead jQuery plugin expects suggestions to a
// JavaScript object, refer to typeahead docs for more info
matches.push({ value: str });
}
});
cb(matches);
};
};
var _data_states_basic = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
$('#the-basics .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
displayKey: 'value',
source: substringMatcher_basic(_data_states_basic)
});
</script>
<p>
2.Using Bloodhound
</p>
<div id="bloodhound">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
<script>
var _data_states_bloodhound = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
var states_bloodhound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: $.map(_data_states_bloodhound, function(state) { return { value: state }; })
});
// kicks off the loading/processing of `local` and `prefetch`
states_bloodhound.initialize();
$('#bloodhound .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
displayKey: 'value',
// `ttAdapter` wraps the suggestion engine in an adapter that
// is compatible with the typeahead jQuery plugin
source: states_bloodhound.ttAdapter()
});
</script>
<p>
3. Pre-fetch (need to replace json URL)
</p>
<div id="prefetch">
<input class="typeahead" type="text" placeholder="Countries">
</div>
<script>
var prefetch_countries = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
prefetch: {
url: 'your json url here',
filter: function(list) {
return $.map(list, function(country) { return { name: country }; });
}
}
});
// kicks off the loading/processing of `local` and `prefetch`
prefetch_countries.initialize();
// passing in `null` for the `options` arguments will result in the default
// options being used
$('#prefetch .typeahead').typeahead(null, {
name: 'prefetch_countries',
displayKey: 'name',
// `ttAdapter` wraps the suggestion engine in an adapter that
// is compatible with the typeahead jQuery plugin
source: prefetch_countries.ttAdapter()
});
</script>
<p>4.Custom Template</p>
<style>
#custom-templates .empty-message {
padding: 5px 10px;
text-align: center;
}
</style>
<div id="custom-templates">
<input class="typeahead" type="text" placeholder="Oscar winners for Best Picture">
</div>
<script>
var _data_states_template_countries = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
var custome_template_countries = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
local: $.map(_data_states_template_countries, function(state) { return { name: state }; })
});
// kicks off the loading/processing of `local` and `prefetch`
custome_template_countries.initialize();
$('#custom-templates .typeahead').typeahead(null, {
displayKey: 'name',
source: custome_template_countries.ttAdapter(),
templates: {
empty: [
'<div class="empty-message">',
'unable to find a country',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<p><strong>{{name}}</strong></p>')
}
});
</script>
<p>5.multiple data set</p>
<style>
#multiple-datasets .league-name {
margin: 0 20px 5px 20px;
padding: 3px 0;
border-bottom: 1px solid #ccc;
}
</style>
<div id="multiple-datasets">
<input class="typeahead" type="text" placeholder="NBA and NHL teams">
</div>
<script>
var _data_nhlteam = [{ "team": "New Jersey Devils" },{ "team": "New York Islanders" },{ "team": "New York Rangers" },{ "team": "Philadelphia Flyers" },{ "team": "Pittsburgh Penguins" },{ "team": "Chicago Blackhawks" },{ "team": "Columbus Blue Jackets" },{ "team": "Detroit Red Wings" },{ "team": "Nashville Predators" },{ "team": "St. Louis Blues" },{ "team": "Boston Bruins" },{ "team": "Buffalo Sabres" },{ "team": "Montreal Canadiens" },{ "team": "Ottawa Senators" },{ "team": "Toronto Maple Leafs" },{ "team": "Calgary Flames" },{ "team": "Colorado Avalanche" },{ "team": "Edmonton Oilers" },{ "team": "Minnesota Wild" },{ "team": "Vancouver Canucks" },{ "team": "Carolina Hurricanes" },{ "team": "Florida Panthers" },{ "team": "Tampa Bay Lightning" },{ "team": "Washington Capitals" },{ "team": "Winnipeg Jets" },{ "team": "Anaheim Ducks" },{ "team": "Dallas Stars" },{ "team": "Los Angeles Kings" },{ "team": "Phoenix Coyotes" },{ "team": "San Jose Sharks" }];
var _data_nbateam = [{ "team": "Boston Celtics" },{ "team": "Dallas Mavericks" },{ "team": "Brooklyn Nets" },{ "team": "Houston Rockets" },{ "team": "New York Knicks" },{ "team": "Memphis Grizzlies" },{ "team": "Philadelphia 76ers" },{ "team": "New Orleans Hornets" },{ "team": "Toronto Raptors" },{ "team": "San Antonio Spurs" },{ "team": "Chicago Bulls" },{ "team": "Denver Nuggets" },{ "team": "Cleveland Cavaliers" },{ "team": "Minnesota Timberwolves" },{ "team": "Detroit Pistons" },{ "team": "Portland Trail Blazers" },{ "team": "Indiana Pacers" },{ "team": "Oklahoma City Thunder" },{ "team": "Milwaukee Bucks" },{ "team": "Utah Jazz" },{ "team": "Atlanta Hawks" },{ "team": "Golden State Warriors" },{ "team": "Charlotte Bobcats" },{ "team": "Los Angeles Clippers" },{ "team": "Miami Heat" },{ "team": "Los Angeles Lakers" },{ "team": "Orlando Magic" },{ "team": "Phoenix Suns" },{ "team": "Washington Wizards" },{ "team": "Sacramento Kings" }];
var nhlTeams = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: _data_nhlteam
});
var nbaTeams = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: _data_nbateam
});
nhlTeams.initialize();
nbaTeams.initialize();
$('#multiple-datasets .typeahead').typeahead({
highlight: true
},
{
displayKey: 'team',
source: nbaTeams.ttAdapter(),
templates: {
header: '<h3 class="league-name">NBA Teams</h3>'
}
},
{
displayKey: 'team',
source: nhlTeams.ttAdapter(),
templates: {
header: '<h3 class="league-name">NHL Teams</h3>'
}
});
</script>
<p>
6. scrollable drop down
</p>
<style>
#scrollable-dropdown-menu .tt-dropdown-menu {
max-height: 100px;
width:600px;
overflow-y: auto;
}
</style>
<div id="scrollable-dropdown-menu">
<input class="typeahead" type="text" placeholder="Countries">
</div>
<script>
var _data_scrollable_dropdown_countries = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
var _data_scrollable_dropdown_countries = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
local: $.map(_data_states_template_countries, function(state) { return { name: state }; })
});
// kicks off the loading/processing of `local` and `prefetch`
_data_scrollable_dropdown_countries.initialize();
$('#scrollable-dropdown-menu .typeahead').typeahead(null, {
name: 'countries',
displayKey: 'name',
source: _data_scrollable_dropdown_countries.ttAdapter()
});
</script>
另外,这个DateRangePicker可以考虑用来选择时间间隔,也是很不错的:
https://github.com/dangrossman/bootstrap-daterangepicker
相关推荐
这个项目的源代码存放在`react-bootstrap-typeahead-master`这个压缩包中。 首先,我们要理解React。React是Facebook开发的一个JavaScript库,专门用于构建用户界面,尤其适合构建单页应用。它的核心理念是使用组件...
玩笑提前打字按文件名或测试名称过滤测试用法安装安装jest (它需要 Jest 26+)和jest-watch-typeahead yarn add --dev jest jest-watch-typeahead# or with NPMnpm install --save-dev jest jest-watch-typeahead将...
Bootstrap 的 Typeahead 依赖于其自身的 JavaScript 组件和 jQuery 库,因此在使用前需确保已引入这两个库。 1. **基本使用** 在 HTML 结构中,你需要为输入框添加 `data-provide="typeahead"` 属性,以标记这是一...
前端项目-bootstrap-3-typeahead,bootstrap 3 typeahead:Twitter的bootstrap 2的typeahead自动完成插件,可以与bootstrap3一起使用。
React-Bootstrap-Typeahead 是一个基于 React.js 和 Bootstrap 的开源库,用于构建可搜索、可选的类型提示组件。这个库提供了强大的功能,如过滤、分组、远程数据加载以及自定义渲染,使得在 Web 应用中实现交互式...
5. **自定义模板和样式**: CoreJS-Typeahead允许开发者自定义建议列表的展示样式和模板,这可以通过提供回调函数或使用预定义的CSS类来实现。这为创建符合项目风格的UI提供了灵活性。 6. **事件处理**: 该库提供了...
vue-bootstrap-typeahead 使用Bootstrap 4和Vue 2的基于list-group的简单预输入/自动完成 安装 从NPM: > npm i vue-bootstrap-typeahead --save 缩小的UMD和CommonJS版本位于“ dist”文件夹中。 该组件也可以...
基于的typeahead,它依赖于进行样式设置,最初是受Twitter的启发的。 它支持单选和多选,并且符合。 尝试。 请注意,文档和示例适用于最新版本,如果您使用的是过时的版本,则可能不再适用。 安装 npm install --...
8. **项目结构**:解压 meteor-bs-typeahead-master 后,我们可以预期会看到一个典型的 Meteor 项目结构,包括 .meteor 目录、client 和 server 目录,以及可能的 tests 和 public 目录等。 9. **使用教程**:为了...
在实际应用中,`draft-js-typeahead-plugin`可以广泛应用于社区论坛、协作平台、社交媒体和企业内部通讯工具,为用户提供方便快捷的提及和标签功能。通过这个插件,开发者可以轻松地将这一流行的功能集成到他们的...
Bootstrap Typeahead 3 是一个基于流行的前端框架Bootstrap的动态搜索建议插件,它为用户提供了实时搜索...在"Bootstrap-3-Typeahead-master"这个压缩包中,应包含了该插件的源码、示例和文档,方便进一步学习和定制。
Typeahead 输入建立在和之上。安装: > pip install django-bootstrap-typeahead 用法: 将django_bootstrap_typeahead添加到 Django 项目的已安装应用程序中创建一个表单并使用TypeaheadField代替ModelChoiceField...
总结,"proto-angular-typeahead"项目展示了如何利用AngularJS的特性,如指令、数据绑定、服务、过滤器和事件监听,来创建一个功能完备的Typeahead组件。这个原型可以作为学习AngularJS和实践Web开发的宝贵资源。
在这个场景中,我们关注的是如何将 Tagsinput 和 Typeahead 这两个组件整合到 Bootstrap 4 中,以便提供更丰富的用户输入体验。 Tagsinput 是一个允许用户输入并以标签形式展示数据的组件,常见于关键词输入或者...
在Bootstrap 3 Typeahead-master这个压缩包中,可能包含了源代码、示例、文档和其他资源,可以帮助开发者更好地理解和使用这个插件。通过深入研究这些内容,你可以掌握如何在自己的项目中有效地利用Bootstrap 3 ...
Bootstrap 中的 Typeahead 组件就是通常所说的自动完成 AutoComplete,功能很强大,上传的包括两个文件一个bootstrap-typeahead.js和一个underscore-min.js,前者基本上可以满足一般需求了,后一个js是使用对象数据时...
$ meteor add cloudspider:autoform-tags-typeahead 用法示例 SomeSchema = new SimpleSchema ( { tags : { type : [ String ] , label : 'Tags' , autoform : { type : 'tagsTypeahead' , } } } ) ; 假设...
用于React ES6和Redux的Typeahead组件 使用Redux和React ES6库编写的Typeahead。 特征 带有ES6支持的React15提前输入 使用Elasticsearch客户支持提前输入(使用elasticsearch软件包) Redux支持 入门 如果您正在...
这可能涉及到下载 "angualr-typeahead-master" 压缩包并将其内容添加到项目的适当位置。 - 接着,在 AngularJS 应用的模块中声明对 "angular-typeahead" 的依赖。 - 然后,在HTML模板中使用 `typeahead` 指令,并...
使用此模块,您将获得: 使用角度指令易于使用的Type Ahead功能缓存结果以避免多次Ajax调用(用户可以定义自己的缓存函数来决定何时进行Ajax调用) 支持多种选择使用步骤: 在脚本和CSS中包含ng-TypeAhead [removed...