bootstrap-tagsinput是一款插件,用于页面tag标签生成。
它支持自己手动输入,同时也能在ajax基础上智能填充输入框内容。
一般的功能,官网上有介绍。不过对于自动填充这块,需要详细说明一下。
bootstrap-tagsinput-angular.js
bootstrap-tagsinput.js
bootstrap-tagsinput.css
bootstrap3-typeahead.min.js(注意,这里需要的这个typeahead和官网上的有所区别。官网的存在问题!)
这里用的是springboot
@Controller @RequestMapping("/tag") public class TagController { @RequestMapping(value = "/list", method = RequestMethod.GET) public @ResponseBody List<Tag> getTagsList(@RequestParam String query) { return new TagServiceImpl().getTagsByName(query); } }返回的格式如下,前台只用到了id和name。
也可以这么返回:[‘java’, ‘php’, ‘c++’]。只要封装成一个List即可。
[ { "id": "001", "createdId": null, "createdName": null, "createdTime": null, "name": "java" }, { "id": "002", "createdId": null, "createdName": null, "createdTime": null, "name": "php" }, { "id": "003", "createdId": null, "createdName": null, "createdTime": null, "name": "c++" } ]