我正在进行freecodecamp的Wikipedia Viewer挑战,当我通过找到的页面进行迭代时,列表的第一项不包含指向Wikiepdia页面的链接。那是为什么?
JS代码:
function getData(){
var search = $("#searchBar").val();
var url = baseUrl + '/w/api.php?action=query&format=json&origin=*&list=prefixsearch&psoffset=max&pssearch='+search;
$.ajax( {
url: url,
dataType: 'json',
type: 'GET',
success: function(data) {
var html="";
var entries = data.query.prefixsearch;
console.log(url);
html+="<ul class='items'>";
for(var i=0;i<entries.length;i++){
html+="<li><h3>"+entries[i].title+"</h3><a href='http://en.wikipedia.org/?curid="+entries[i].pageid+"'</a></li>";
}
html+="</ul>";
$(".entries").html(html);
}
});
}
Html代码:
<div class="entries">
</div>
答案 0 :(得分:1)
正如James在评论中指出的那样,您的代码输出>
而没有结束html+="<li><h3>"+entries[i].title+"</h3><a href='http://en.wikipedia.org/?curid="+entries[i].pageid+"'</a></li>";
且没有文字。
变化:
html+="<li><a href='http://en.wikipedia.org/?curid="+entries[i].pageid+"'><h3>"+entries[i].title+"</h3></a></li>";
进入这个:
function getData() {
var search = $("#searchBar").val();
var url = baseUrl + '/w/api.php?action=query&format=json&origin=*&list=prefixsearch&psoffset=max&pssearch=' + search;
$.ajax({
url: url,
dataType: 'json',
type: 'GET',
success: function(data) {
var html = "";
var entries = data.query.prefixsearch;
console.log(url);
html += "<ul class='items'>";
for (var i = 0; i < entries.length; i++) {
html+="<li><a href='http://en.wikipedia.org/?curid="+entries[i].pageid+"'><h3>"+entries[i].title+"</h3></a></li>";
}
html += "</ul>";
$(".entries").html(html);
}
});
}
完整代码
#Test array
$array = "Dog", "Cat", "Mouse", "Tiger"
#Location of the Excel file to edit
$FileLoc = "Q:\Cutsheet.xlsx"
#Create Excel Com Object, and display it
$excel = new-object -com Excel.Application
$excel.visible = $true
#Open Workbook
$workbooks = $excel.workbooks.Open($FileLoc)
$worksheets = $workbooks.Worksheets
$worksheet = $worksheets.item("DATA")
#opens inventory workbook
$source = $excel.workbooks.Open("Q:\inventory.xlsx")
$sourceSheets = $source.Worksheets
<#
#This loop will search for match element of the array with a corresponding cell on an excel spreadsheet.
#That cell is grouped with several names of inventory worksheet names. The script will copy each inventory
#and append it to the existing cutsheet.
#>
foreach($element in $array) {
for ($i = 9; $i -lt 20; $i++) {
if ($worksheet.Cells.Item($i, 1).Text -eq $element) {
$j = 2
while ($worksheet.Cells.Item($i, $j).Text -ne "") {
Write-Host $worksheet.Cells.Item($i, $j).Value2
$name = $worksheet.Cells.Item($i, $j).Value2
$sourceSheet = $sourceSheets.Item($name)
$sourceSheet.Copy([system.type]::missing, $worksheets)
$j++
}
}
}
}