我遇到了自动完成小部件的问题,我从这里得到autocomplete
当有一个数组(如源代码示例中的那个)时,它工作正常但是当我放置一些(json_encode($ rowData)的数据时,它根据检索到的数据不提供建议
顺便说一下,我使用PHPexcel从excel表中检索数据到数据数组
这是我的代码......
<?php
set_include_path(implode(PATH_SEPARATOR, [
realpath(__DIR__ . '/Classes'), // assuming Classes is in the same directory as this script
get_include_path()
]));
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';
require_once 'PHPExcel.php';
$file= "./uploads/".$_GET["filename"];
//if you want to try it you can use this and comment line on the above
// $inputFileName = './sampleData/yourexcelname.xls';
$inputFileName = ($file);
// Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
// Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
// Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++){
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE);
var_dump($rowData); // Insert row data array into your database of choice here
echo "-----------------as json encode---------------";
var_dump(json_encode($rowData));
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function() {
var availableTags =<?php echo json_encode($rowData); ?>;
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
我可以为您提供一个简单的Excel图像:
我应该怎么做才能让我的excel单元格出现在自动完成搜索框中?