我使用typeahead作为一个非常简单的网络应用程序的自动提示。我是javascript和jQuery的新手。 Web应用程序是一个输入,它将搜索iTunes商店并在用户输入时建议结果。
我有一个版本正在运行,它将根据用户输入的内容检索歌曲名称。但是,我希望能够做的是使用其他值更新一些隐藏字段(例如,艺术家姓名,曲目ID,预览网址等)。我正在尝试使用filter
选项来完成此操作,但我现在只在我的搜索中找回undefined
。
此外,一般提示:javascript和jQuery将不胜感激。这是我想要开展的下一项技能。
相关代码:
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>HOLLAND</title>
<meta charset="utf-8">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="//netsh.pp.ua/upwork-demo/1/js/typeahead.js"></script>
<style>
h1 {
font-size: 20px;
color: #111;
}
.content {
width: 80%;
margin: 0 auto;
margin-top: 50px;
}
input[type=submit] {
border: none;
border-radius: 8px 8px 8px 8px;
height: 47px;
width: 60px;
vertical-align: bottom;
}
.tt-hint,
.song {
border: 2px solid #CCCCCC;
border-radius: 8px 8px 8px 8px;
font-size: 24px;
height: 45px;
line-height: 30px;
outline: medium none;
padding: 8px 12px;
width: 400px;
}
.tt-dropdown-menu {
width: 400px;
margin-top: 5px;
padding: 8px 12px;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 8px 8px 8px 8px;
font-size: 18px;
color: #111;
background-color: #F1F1F1;
}
</style>
<script>
var resultList, d;
$(document).ready(function() {
$('input.song').typeahead({
name: 'song',
remote: {
url: '/Playlist/search.php?query=%QUERY',
filter: function(data) { <-- THIS IS WHERE I NEED ASSISTANCE
retval = [];
for (var i = 0; i < data.length; i++) {
retval.push({
value: data[i].trackId,
artistName: data[i].artistName,
});
}
return retval;
}
}
}).on('song:select', function(ev, suggestion) {
$('#songID').val(d[resultList.indexOf(suggestion)].trackId);
});
});
function printArray(arr){
for(var i = 0; i < arr.length; i++){
if(arr[i] instanceof Array){
printArray(arr[i]);
}else{
console.log(arr[i]);
}
}
}
</script>
</head>
<body>
<div class="content">
<h2>Playlist</h2>
<form>
<h1>Search Apple Music</h1>
<input type="text" name="song" size="30" class="song" placeholder="Please enter song name">
<input type="hidden" name ="songID">
<input type="submit" name="submit" value="Add">
</form>
</div>
</body>
</html>
的search.php
<?php
$key = $_GET['query'];
$searchString = "https://itunes.apple.com/search?term=" . urlencode($key) . "&limit=10&entity=song";
$array = array();
// Initiate curl
$ch = curl_init();
//No header return
curl_setopt($ch, CURLOPT_HEADER, false);
//Use proxy
curl_setopt($ch, CURLOPT_PROXY, "naproxy.gm.com");
curl_setopt($ch, CURLOPT_PROXYPORT, "80");
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $searchString);
// Execute
$result=curl_exec($ch);
// Will dump a beauty json :3
if(curl_errno($ch)) {
echo curl_error($ch);
}
else{
$obj = json_decode($result, true);
}
// Closing
curl_close($ch);
/*
foreach($obj['results'] as $row => $value) {
$array[] = $value['trackName'] . " by " . $value['artistName'];
}
*/
foreach($obj['results'] as $row => $value) {
$array[$row] = array
(
'trackId', $value['trackId'],
'trackName', $value['trackName'],
'artistName',$value['artistName'],
'previewURL', $value ['artworkUrl30']
);
}
echo $array;
?>
来自iTunes的回复
{
"resultCount": 10,
"results": [
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902180909,
"trackId": 902180917,
"artistName": "Lady Gaga",
"collectionName": "Born This Way (Bonus Track Version)",
"trackName": "Born This Way",
"collectionCensoredName": "Born This Way (Bonus Track Version)",
"trackCensoredName": "Born This Way",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way\/id902180909?i=902180917&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way\/id902180909?i=902180917&uo=4",
"previewUrl": "http:\/\/a463.phobos.apple.com\/us\/r30\/Music1\/v4\/d5\/3c\/07\/d53c0773-ff35-1fe5-9be2-815038285c08\/mzaf_4465142801402798156.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/100x100bb.jpg",
"collectionPrice": 10.99,
"trackPrice": 1.29,
"releaseDate": "2013-01-01T08:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 22,
"trackNumber": 2,
"trackTimeMillis": 260258,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902096524,
"trackId": 902096558,
"artistName": "Lady Gaga",
"collectionName": "Born This Way",
"trackName": "Born This Way",
"collectionCensoredName": "Born This Way",
"trackCensoredName": "Born This Way",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way\/id902096524?i=902096558&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way\/id902096524?i=902096558&uo=4",
"previewUrl": "http:\/\/a459.phobos.apple.com\/us\/r30\/Music1\/v4\/c7\/2a\/83\/c72a8341-88b7-c65d-09dc-c333de92bb0c\/mzaf_4381737056492150878.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is1.mzstatic.com\/image\/thumb\/Music3\/v4\/b9\/d2\/e8\/b9d2e809-eb0b-d2df-193b-5bc99b5e5ecf\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is1.mzstatic.com\/image\/thumb\/Music3\/v4\/b9\/d2\/e8\/b9d2e809-eb0b-d2df-193b-5bc99b5e5ecf\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is1.mzstatic.com\/image\/thumb\/Music3\/v4\/b9\/d2\/e8\/b9d2e809-eb0b-d2df-193b-5bc99b5e5ecf\/source\/100x100bb.jpg",
"collectionPrice": 7.99,
"trackPrice": 1.29,
"releaseDate": "2011-02-11T08:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 14,
"trackNumber": 2,
"trackTimeMillis": 260258,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902180909,
"trackId": 902180935,
"artistName": "Lady Gaga",
"collectionName": "Born This Way (Bonus Track Version)",
"trackName": "The Edge of Glory",
"collectionCensoredName": "Born This Way (Bonus Track Version)",
"trackCensoredName": "The Edge of Glory",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/the-edge-of-glory\/id902180909?i=902180935&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/the-edge-of-glory\/id902180909?i=902180935&uo=4",
"previewUrl": "http:\/\/a642.phobos.apple.com\/us\/r30\/Music4\/v4\/bb\/93\/f6\/bb93f6dd-b09f-6378-9097-e41fab0a50e7\/mzaf_2685820553066586847.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/100x100bb.jpg",
"collectionPrice": 10.99,
"trackPrice": 1.29,
"releaseDate": "2013-01-01T08:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 22,
"trackNumber": 17,
"trackTimeMillis": 321545,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902180909,
"trackId": 902180934,
"artistName": "Lady Gaga",
"collectionName": "Born This Way (Bonus Track Version)",
"trackName": "Yo\u00fc and I",
"collectionCensoredName": "Born This Way (Bonus Track Version)",
"trackCensoredName": "Yo\u00fc and I",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/yo%C3%BC-and-i\/id902180909?i=902180934&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/yo%C3%BC-and-i\/id902180909?i=902180934&uo=4",
"previewUrl": "http:\/\/a37.phobos.apple.com\/us\/r30\/Music1\/v4\/b3\/d0\/51\/b3d05174-db69-be68-272b-1b1dd35360d9\/mzaf_7395703188902498297.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/100x100bb.jpg",
"collectionPrice": 10.99,
"trackPrice": 1.29,
"releaseDate": "2011-05-23T07:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 22,
"trackNumber": 16,
"trackTimeMillis": 307364,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 716415763,
"trackId": 716415953,
"artistName": "Lady Gaga",
"collectionName": "NOW That's What I Call a Workout",
"trackName": "Born This Way (Bimbo Jones Club Remix)",
"collectionCensoredName": "NOW That's What I Call a Workout",
"trackCensoredName": "Born This Way (Bimbo Jones Club Remix)",
"collectionArtistId": 4035426,
"collectionArtistName": "Various Artists",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way-bimbo-jones-club-remix\/id716415763?i=716415953&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way-bimbo-jones-club-remix\/id716415763?i=716415953&uo=4",
"previewUrl": "http:\/\/a294.phobos.apple.com\/us\/r30\/Music3\/v4\/25\/47\/e8\/2547e80d-c74c-7cf4-7905-041c7f7ec259\/mzaf_1883593890824568199.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is5.mzstatic.com\/image\/thumb\/Music6\/v4\/a5\/ed\/99\/a5ed99e5-ca11-2a34-a72d-e86b2e11a1ba\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is5.mzstatic.com\/image\/thumb\/Music6\/v4\/a5\/ed\/99\/a5ed99e5-ca11-2a34-a72d-e86b2e11a1ba\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is5.mzstatic.com\/image\/thumb\/Music6\/v4\/a5\/ed\/99\/a5ed99e5-ca11-2a34-a72d-e86b2e11a1ba\/source\/100x100bb.jpg",
"collectionPrice": 11.99,
"trackPrice": -1,
"releaseDate": "2012-12-18T08:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 18,
"trackNumber": 1,
"trackTimeMillis": 284453,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Fitness & Workout",
"isStreamable": false
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902180909,
"trackId": 902180936,
"artistName": "Lady Gaga",
"collectionName": "Born This Way (Bonus Track Version)",
"trackName": "Born This Way",
"collectionCensoredName": "Born This Way (Bonus Track Version)",
"trackCensoredName": "Born This Way (The Country Road Version)",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way-the-country-road-version\/id902180909?i=902180936&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/born-this-way-the-country-road-version\/id902180909?i=902180936&uo=4",
"previewUrl": "http:\/\/a470.phobos.apple.com\/us\/r30\/Music4\/v4\/76\/79\/3d\/76793d4c-0683-3793-0b02-7e8ced3ec1e1\/mzaf_5908951428023709023.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/100x100bb.jpg",
"collectionPrice": 10.99,
"trackPrice": 1.29,
"releaseDate": "2011-05-23T07:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 22,
"trackNumber": 18,
"trackTimeMillis": 261276,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902180909,
"trackId": 902180916,
"artistName": "Lady Gaga",
"collectionName": "Born This Way (Bonus Track Version)",
"trackName": "Marry the Night",
"collectionCensoredName": "Born This Way (Bonus Track Version)",
"trackCensoredName": "Marry the Night",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/marry-the-night\/id902180909?i=902180916&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/marry-the-night\/id902180909?i=902180916&uo=4",
"previewUrl": "http:\/\/a211.phobos.apple.com\/us\/r30\/Music4\/v4\/74\/30\/24\/743024be-2c46-b876-5c39-ba6bdf94ec72\/mzaf_1169912516356657975.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/100x100bb.jpg",
"collectionPrice": 10.99,
"trackPrice": 1.29,
"releaseDate": "2013-01-01T08:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 22,
"trackNumber": 1,
"trackTimeMillis": 264523,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902180909,
"trackId": 902180938,
"artistName": "Lady Gaga",
"collectionName": "Born This Way (Bonus Track Version)",
"trackName": "Judas",
"collectionCensoredName": "Born This Way (Bonus Track Version)",
"trackCensoredName": "Judas (DJ White Shadow Remix)",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/judas-dj-white-shadow-remix\/id902180909?i=902180938&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/judas-dj-white-shadow-remix\/id902180909?i=902180938&uo=4",
"previewUrl": "http:\/\/a1915.phobos.apple.com\/us\/r30\/Music4\/v4\/20\/95\/05\/2095055f-c724-b689-72bc-d0d747d5379d\/mzaf_3035200198497304749.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/100x100bb.jpg",
"collectionPrice": 10.99,
"trackPrice": 1.29,
"releaseDate": "2011-05-23T07:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 22,
"trackNumber": 19,
"trackTimeMillis": 247483,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 277293880,
"collectionId": 902180909,
"trackId": 902180920,
"artistName": "Lady Gaga",
"collectionName": "Born This Way (Bonus Track Version)",
"trackName": "Judas",
"collectionCensoredName": "Born This Way (Bonus Track Version)",
"trackCensoredName": "Judas",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/lady-gaga\/id277293880?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/judas\/id902180909?i=902180920&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/judas\/id902180909?i=902180920&uo=4",
"previewUrl": "http:\/\/a53.phobos.apple.com\/us\/r30\/Music4\/v4\/bc\/9b\/d5\/bc9bd511-00b9-ebad-73df-62cdf01a26b4\/mzaf_8671438699719321037.plus.aac.p.m4a",
"artworkUrl30": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is3.mzstatic.com\/image\/thumb\/Music1\/v4\/94\/8f\/b9\/948fb9ce-de93-fe33-e7b5-a8bdf5580178\/source\/100x100bb.jpg",
"collectionPrice": 10.99,
"trackPrice": 1.29,
"releaseDate": "2011-04-15T07:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 22,
"trackNumber": 4,
"trackTimeMillis": 249071,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Pop",
"isStreamable": true
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 412537193,
"collectionId": 446108937,
"trackId": 446108958,
"artistName": "Born This Way",
"collectionName": "Poker Face - Single",
"trackName": "Poker Face",
"collectionCensoredName": "Poker Face - Single",
"trackCensoredName": "Poker Face",
"artistViewUrl": "https:\/\/itunes.apple.com\/us\/artist\/born-this-way\/id412537193?uo=4",
"collectionViewUrl": "https:\/\/itunes.apple.com\/us\/album\/poker-face\/id446108937?i=446108958&uo=4",
"trackViewUrl": "https:\/\/itunes.apple.com\/us\/album\/poker-face\/id446108937?i=446108958&uo=4",
"previewUrl": "http:\/\/a578.phobos.apple.com\/us\/r30\/Music\/1b\/4b\/13\/mzm.uzkuoblk.aac.p.m4a",
"artworkUrl30": "http:\/\/is4.mzstatic.com\/image\/thumb\/Music6\/v4\/95\/b5\/95\/95b59505-1d03-6a6d-4e36-e3b7219f7605\/source\/30x30bb.jpg",
"artworkUrl60": "http:\/\/is4.mzstatic.com\/image\/thumb\/Music6\/v4\/95\/b5\/95\/95b59505-1d03-6a6d-4e36-e3b7219f7605\/source\/60x60bb.jpg",
"artworkUrl100": "http:\/\/is4.mzstatic.com\/image\/thumb\/Music6\/v4\/95\/b5\/95\/95b59505-1d03-6a6d-4e36-e3b7219f7605\/source\/100x100bb.jpg",
"collectionPrice": 1.98,
"trackPrice": 0.99,
"releaseDate": "2011-06-17T07:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 2,
"trackNumber": 1,
"trackTimeMillis": 238653,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Dance",
"isStreamable": true
}
]
}
我怀疑问题在于我如何返回/解析数组。当我查看控制台时,resultList被设置但看起来我想要的键(例如trackId,trackName,artistName等)实际上存储为数组中的值。
非常感谢您的协助。我正在尝试使用数组中返回的trackID的值更新隐藏的输入songID(我还会添加一些其他的,如我所提到的,例如艺术家和预览URL)。
谢谢!
答案 0 :(得分:0)
像这样改变你的代码:
filter: function(data) { <-- THIS IS WHERE I NEED ASSISTANCE
$('name["songID"]').val(data[i].trackId);
retval = [];
..............
.........
...