1

我可以看到一个很好的控制

http://timschlechter.github.io/bootstrap-tagsinput/examples/

但是基于它我尝试了下面的代码它没有用,任何人都可以帮助我

<script type="text/javascript" src="jquery-1.10.2.min.js" ></script>

<script src="http://timschlechter.github.io/bootstrap-tagsinput/examples/bower_components/angular/angular.min.js"></script>
<script src="http://timschlechter.github.io/bootstrap-tagsinput/examples/bower_components/google-code-prettify-lite/prettify.js"></script>
<script src="http://timschlechter.github.io/bootstrap-tagsinput/examples/bootstrap-2.3.2/js/bootstrap.min.js"></script>
<script src="http://timschlechter.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.js"></script>
<script src="http://timschlechter.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput-angular.js"></script>

<body>
<br />
<input type="text" value="" data-role="tagsinput"  />
<br />
</body>
<script>
$('input').tagsinput({
  typeahead: {
    source: [{"value":1,"text":"Amsterdam"},
{"value":4,"text":"Washington"},
{"value":7,"text":"Sydney"},
{"value":10,"text":"Beijing"},
{"value":13,"text":"Cairo"}]
  }
});
</script>
4

2 回答 2

1

这是因为一个已知的错误: https ://github.com/TimSchlechter/bootstrap-tagsinput/issues/42

要解决此问题,请勿将 data-role="tagsinput" 和 $('input').tagsinput(...) 一起使用。

tagsinput 不是函数,使用 bootstrap 3 和 tags-input 插件

于 2014-03-19T12:14:42.703 回答
0

我在一个项目中使用相同的插件 预输入源的问题它需要是一个带有简单元素的 json 没有对象

看看这个小提琴,我相信它会帮助你

小提琴

$('input').tagsinput({
    typeahead: {
        source: function (query, process) {
            cities = [];
            map = {};

            var data = [{
                "value": 1,
                    "text": "Amsterdam"
            }, {
                "value": 4,
                    "text": "Washington"
            }, {
                "value": 7,
                    "text": "Sydney"
            }, {
                "value": 10,
                    "text": "Beijing"
            }, {
                "value": 13,
                    "text": "Cairo"
            }];

            $.each(data, function (i, city) {
                map[city.text] = city;
                cities.push(city.text);
            });

            return (cities);
        }
    }
});

预取的 Json

cities = [];
map = {};

var preFetchResult = function (query, callback) {
    $.get("/cities", {
        "data": query
    }, function (data) {
        $.each(data, function (i, city) {
            map[city.text] = city;
            cities.push(city.text);
        });
    });
};

preFetchResult.done(function (response) {
    $('input').tagsinput({
        typeahead: {
            source: function (query, process) {
                return (cities);
            }
        }
    });
});
于 2013-11-20T11:09:31.407 回答