AutoComplete jQuery Using JSON data

前端 未结 4 1012
醉酒成梦
醉酒成梦 2021-01-18 12:08

Imagine a json file with the following data:

[
    {
        color: \"red\",
        value: \"#f00\"
    },
    {
        color: \"green\",
        value: \"         


        
4条回答
  •  春和景丽
    2021-01-18 12:47

    You need to change your JSON object to use the "label" property. From the docs:

    An Array of Objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]

    The label property is displayed in the suggestion menu. The value will be inserted into the input element after the user selected something from the menu. If just one property is specified, it will be used for both, eg. if you provide only value-properties, the value will also be used as the label.

    Then, you need to set the values of the other text fields when the "change" or "select" events are fired.

提交回复
热议问题