我正在尝试使用服务器的JSON输出作为自动完成功能的源。我阅读了Autocomplete文档,它确实说Array对象被接受为源类型。有人可以告诉我这里哪里出错吗?
> dput(SampleFinal)
structure(list(Firm = c("ENG", "ENG", "ENG", "ENG", "ENG", "ENG",
"ENG", "ENG", "ENG", "ENG", "ENG", "ENG", "ENG", "ENG", "ENG",
"ENG", "ENG", "ENG", "ENG", "ENG", "ENG", "ENG", "ENG", "ENG",
"ENG", "ENG", "ENG", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS",
"AUS", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS",
"AUS", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS", "AUS",
"AUS", "AUS", "AUS", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ",
"NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ",
"NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ"), Date = structure(c(1451865600,
1451952000, 1452038400, 1452124800, 1452211200, 1452470400, 1452556800,
1452643200, 1452729600, 1452816000, 1453075200, 1453161600, 1453248000,
1453334400, 1453420800, 1453680000, 1453852800, 1453939200, 1454025600,
1454284800, 1454371200, 1454457600, 1454544000, 1454630400, 1454889600,
1454976000, 1455062400, 1451865600, 1451952000, 1452038400, 1452124800,
1452211200, 1452470400, 1452556800, 1452643200, 1452729600, 1452816000,
1453075200, 1453161600, 1453248000, 1453334400, 1453420800, 1453680000,
1453852800, 1453939200, 1454025600, 1454284800, 1454371200, 1454457600,
1454544000, 1454630400, 1454889600, 1454976000, 1455062400, 1451865600,
1451952000, 1452038400, 1452124800, 1452211200, 1452470400, 1452556800,
1452643200, 1452729600, 1452816000, 1453075200, 1453161600, 1453248000,
1453334400, 1453420800, 1453680000, 1453852800, 1453939200, 1454025600,
1454284800, 1454371200, 1454457600, 1454544000, 1454630400, 1454889600,
1454976000, 1455062400), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Week = c("1", "1", "1", "1", "1", "2", "2", "2", "2", "2",
"3", "3", "3", "3", "3", "4", "4", "4", "4", "4", "5", "5",
"5", "5", "5", "NA", "NA", "1", "1", "1", "1", "1", "2",
"2", "2", "2", "2", "3", "3", "3", "3", "3", "4", "4", "4",
"4", "4", "5", "5", "5", "5", "5", "NA", "NA", "1", "1",
"1", "1", "1", "2", "2", "2", "2", "2", "3", "3", "3", "3",
"3", "4", "4", "4", "4", "4", "5", "5", "5", "5", "5", "NA",
"NA"), TotalSales = c("200", "200", "200", "200", "200",
"155", "155", "155", "155", "155", "195", "195", "195", "195",
"195", "150", "150", "150", "150", "150", "155", "155", "155",
"155", "155", "NA", "NA", "140", "140", "140", "140", "140",
"145", "145", "145", "145", "145", "150", "150", "150", "150",
"150", "155", "155", "155", "155", "155", "160", "160", "160",
"160", "160", "NA", "NA", "120", "120", "120", "120", "120",
"125", "125", "125", "125", "125", "130", "130", "130", "130",
"130", "135", "135", "135", "135", "135", "140", "140", "140",
"140", "140", "NA", "NA"), AP = c("75451.061100000006", "70753.717799999999",
"72662.012000000002", "77799.73", "79414.439100000003", "81469.528600000005",
"81029.153900000005", "82203.488299999997", "90183.046499999997",
"91850.015899999999", "92516.806299999997", "94350.470199999996",
"91683.321500000005", "95017.260500000004", "97184.319600000003",
"97684.409100000004", "98184.505099999995", "99017.989799999996",
"100851.6537", "99684.773799999995", "99518.079400000002",
"100351.5641", "99684.773799999995", "99518.079400000002",
"100018.1689", "NA", "NA", "81469.528600000005", "81029.153900000005",
"82203.488299999997", "90183.046499999997", "91850.015899999999",
"104852.383", "106019.2565", "100518.2585", "98017.804300000003",
"108686.40519999999", "81469.528600000005", "81029.153900000005",
"82203.488299999997", "90183.046499999997", "91850.015899999999",
"110686.77619999999", "111853.64969999999", "115354.2831",
"115854.379", "116687.86380000001", "104852.383", "106019.2565",
"100518.2585", "98017.804300000003", "81469.528600000005",
"NA", "NA", "75451.061100000006", "70753.717799999999", "72662.012000000002",
"77799.73", "79414.439100000003", "81469.528600000005", "81029.153900000005",
"82203.488299999997", "90183.046499999997", "91850.015899999999",
"92516.806299999997", "94350.470199999996", "91683.321500000005",
"95017.260500000004", "97184.319600000003", "97684.409100000004",
"98184.505099999995", "99017.989799999996", "100851.6537",
"99684.773799999995", "99518.079400000002", "100351.5641",
"99684.773799999995", "99518.079400000002", "100018.1689",
"NA", "NA"), BG = c("104852.383", "106019.2565", "100518.2585",
"98017.804300000003", "108686.40519999999", "114854.19990000001",
"116021.07339999999", "117354.6541", "113020.53599999999",
"114020.7151", "110686.77619999999", "111853.64969999999",
"115354.2831", "115854.379", "116687.86380000001", "117021.25260000001",
"115187.58869999999", "114354.10400000001", "113520.6192",
"109853.2914", "109186.50109999999", "107686.226", "107352.83719999999",
"106852.74129999999", "116687.86380000001", "NA", "NA", "75451.061100000006",
"70753.717799999999", "72662.012000000002", "77799.73", "79414.439100000003",
"81469.528600000005", "81029.153900000005", "82203.488299999997",
"90183.046499999997", "91850.015899999999", "92516.806299999997",
"94350.470199999996", "91683.321500000005", "95017.260500000004",
"97184.319600000003", "97684.409100000004", "98184.505099999995",
"99017.989799999996", "100851.6537", "99684.773799999995",
"99518.079400000002", "100351.5641", "99684.773799999995",
"99518.079400000002", "100018.1689", "NA", "NA", "81469.528600000005",
"81029.153900000005", "82203.488299999997", "90183.046499999997",
"91850.015899999999", "104852.383", "106019.2565", "100518.2585",
"98017.804300000003", "108686.40519999999", "81469.528600000005",
"81029.153900000005", "82203.488299999997", "90183.046499999997",
"91850.015899999999", "110686.77619999999", "111853.64969999999",
"115354.2831", "115854.379", "116687.86380000001", "104852.383",
"106019.2565", "100518.2585", "98017.804300000003", "81469.528600000005",
"NA", "NA"), CK = c("81469.528600000005", "81029.153900000005",
"82203.488299999997", "90183.046499999997", "91850.015899999999",
"104852.383", "106019.2565", "100518.2585", "98017.804300000003",
"108686.40519999999", "81469.528600000005", "81029.153900000005",
"82203.488299999997", "90183.046499999997", "91850.015899999999",
"110686.77619999999", "111853.64969999999", "115354.2831",
"115854.379", "116687.86380000001", "104852.383", "106019.2565",
"100518.2585", "98017.804300000003", "81469.528600000005",
"NA", "NA", "104852.383", "106019.2565", "100518.2585", "98017.804300000003",
"108686.40519999999", "114854.19990000001", "116021.07339999999",
"117354.6541", "113020.53599999999", "114020.7151", "110686.77619999999",
"111853.64969999999", "115354.2831", "115854.379", "116687.86380000001",
"117021.25260000001", "115187.58869999999", "114354.10400000001",
"113520.6192", "109853.2914", "109186.50109999999", "107686.226",
"107352.83719999999", "106852.74129999999", "116687.86380000001",
"NA", "NA", "75451.061100000006", "70753.717799999999", "72662.012000000002",
"77799.73", "79414.439100000003", "81469.528600000005", "81029.153900000005",
"82203.488299999997", "90183.046499999997", "91850.015899999999",
"92516.806299999997", "94350.470199999996", "91683.321500000005",
"95017.260500000004", "97184.319600000003", "97684.409100000004",
"98184.505099999995", "99017.989799999996", "100851.6537",
"99684.773799999995", "99518.079400000002", "100351.5641",
"99684.773799999995", "99518.079400000002", "100018.1689",
"NA", "NA")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-81L), .Names = c("Firm", "Date", "Week", "TotalSales", "AP",
"BG", "CK"))
这是我从服务器(JSON编码)返回的内容:
jq( document ).ready(function() {
jq("body").css({overflow:'hidden'});
jq.getJSON("<?php echo Mage::getBaseUrl() . "setsession/index/getarea"; ?>",
function(data) {
jq( "#autocomplete-1" ).autocomplete({
source: data,
select: function(event, ui) {
alert(ui.item.area_id);
jq("#splash_area").val(ui.item.area_id);
return false;
}
});
}
);
});
答案 0 :(得分:1)
从文档中可以看出An array of objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]
。
http://api.jqueryui.com/autocomplete/#option-source
您的对象未以此方式定义。所以像你的例子
[{value:“1”,label:“DLF Phase 1”},{value:“2”,label:“DLF Phase 2”}]