javascript - Select2.js v4.0: how set the default selected value with a local array data source? -


by using select2.js v4 plugin , how set default selected value when use local array data source?

for example code

var data_names = [{   id: 0,   text: "henri", }, {   id: 1,   text: "john", }, {   id: 2,   text: "victor", }, {   id: 3,   text: "marie", }];  $('select').select2({   data: data_names, }); 

how set id 3 default selected value?

$('.select').select2({         data: data_names,     }).select2("val",3); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -