我从后端收到以下JSON。
[{"video_name":"video1","video_id":"74"},{"video_name":"videoactual","video_id":"89"}]
我正在使用bootstrap类型进行自动完成目的
这是我的代码
目前在选择时,我可以获得视频名称
我如何获得所选的视频ID?
var videoNames = new Array();
var videoIds = new Object();
$('#linkvideoname').typeahead({
updater: function(selection){
alert("You selected: " + selection)
},
source: function(query, process) {
$.ajax({
url: url + '/videodetails',
dataType: "json",
data: query,
contentType: "application/json; charset=utf-8",
type: "POST",
success: function(data) {
$.each( data, function ( index, video )
{
videoNames.push( video.video_name );
videoIds[video.name] = video.video_id;
} );
process(videoNames);
}
});
},
});