jq循环追加下拉多选

67 阅读1分钟

    let ceshidata =[
                        {
                            "key": "999",
                            "val": "上海2222()",
                            "optional_res": 1
                        },
                        {
                            "key": "101160",
                            "val": "上海2)",
                            "optional_res": 0
                        },
                        {
                            "key": "101154",
                            "val": "江苏",
                            "optional_res": 1
                        },
                        {
                            "key": "100885",
                            "val": "北京3",
                            "optional_res": 0
                        },
                        {
                            "key": "3",
                            "val": "南京",
                            "optional_res": 0
                        },
                    ]


  var checkbox = $('<input />').attr({
                                type: 'checkbox',
                                value: customer.key,// 使用key作为复选框的值
                                disabled:customer.optional_res===1?false:true
                            });
                            var label = $('<label>').append(checkbox, customer.val); // 使用val作为复选框的文本
                            var divs = $('<div>').addClass(customer.key).append(label);