如何使用来自json对象的数据填充“ multiselect”?

问题描述

我似乎无法用来自json对象的数据填充multiselect字段。无论我使用哪个多选,它都无济于事。数据以检查模式显示,但不以字体显示。 它应该看起来像这样。

enter image description here

但是就是这样。没有选择了。

enter image description here

我的html代码:

<div>
   <span>Tags</span>
   <select id="choices-multiple-remove-button" placeholder="Select upto 5 tags"   name="tags" multiple></select>
</div>
            

我的js代码:

    success: function (data) {
    console.log(data);

    $.each(data,function (index,value) {
        var tagOption = ('<option value=' + value.Id + '>' + value.Name + '</option>');
        console.log(value.Name);
        $('#choices-multiple-remove-button').append(tagOption);

    });


    $(document).ready(function () {
        var multipleCancelButton = new Choices('#choices',{
            removeItemButton: true,maxItemCount: 5,searchResultLimit: 1,renderChoiceLimit: 2
        });
    });

我的json数据:

  {
    "Id": 1,"Name": "Tasty","TimeStamp": null,"FOodOrTravel": 1
  },{
    "Id": 2,"Name": "Smells Bad",{
    "Id": 3,"Name": "Spicy",{
    "Id": 4,"Name": "Expensive","FOodOrTravel": 1
  }

console.log(数据)

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)