当前位置: 代码迷 >> JavaScript >> jquery autocomplate解决思路
  详细解决方案

jquery autocomplate解决思路

热度:404   发布时间:2013-12-21 20:16:01.0
jquery autocomplate

$.ajax({
                type: "POST",
                url: "AutoComplateHandler.ashx",
                success: function (data, status) {
                    if (status == "success") {
                        var source = [
                            { "Name": "Java", "Age": 22 },
                            { "Name": "C++", "Age": 232 },
                            { "Name": "PHP", "Age": 233 },
                            { "Name": "Python", "Age": 231 },
                            { "Name": "Perl", "Age": 230 },
                            { "Name": "Asp", "Age": 213 },
                            { "Name": "C++", "Age": 23 }
                            ];
                        $("#txtComplate").autocomplete({
                            source: source, //["Java","C++","PHP","Python"] 
//如何提取json Name集合
                            select: function (event, ui) {
                                alert(ui.item.value);//获取当期选择的value 如何根据当期选中Name
//属性(如:Java)的值获取相对应的Age值
                            }
                        });
                    }
                }
            });

------解决方案--------------------
an array of objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]

键值名称改成label和value,不支持你那种格式的数据,要不你就需要手动转换了


	        var source = [
                            { "Name": "Java", "Age": 22 },
                            { "Name": "C++", "Age": 232 },
                            { "Name": "PHP", "Age": 233 },
  相关解决方案