Unable to select a result from the select2 search results

后端 未结 4 957
庸人自扰
庸人自扰 2020-12-06 11:05

I am using the select2 for on of my search boxes. I\'m getting the results from my URL but I\'m not able to select an option from it. I want to use the \'product.productName

4条回答
  •  温柔的废话
    2020-12-06 11:18

    The id param can be a string related to the object property name, and must be in the root of the object. Text inside data object.

    var fruits = [{code: 222, fruit: 'grape', color:'purple', price: 2.2},
      {code: 234,fruit: 'banana', color:'yellow', price: 1.9} ];
    
    $(yourfield).select2(
     {
       id: 'code',
       data: { results: fruits, text: 'fruit' }
     }
    );
    

提交回复
热议问题