Select2 - use JSON as local data

后端 未结 3 980
暖寄归人
暖寄归人 2020-12-14 09:53

I can get this to work...

var options = [{id: 1, text: \'Adair, Charles\'}]  
$(\'#names\').select2({
    data: options,
})

But i cant work

3条回答
  •  太阳男子
    2020-12-14 10:21

    As an update for this old post, having custom properties for id and text is not directly supported anymore since 4.0.0+ version.

    See here on "The id and text properties are strictly enforced" text block. You must create a $.map object as a workaround.

    Even more, working with an [input type="hidden"] is now deprecated as all core select2 options now support the [select] html object.

    Have a look to John S' answer on this post as well.

提交回复
热议问题