我想使用modal,所以我从ajax获取数据值。 数据类似于[{'source_name':'인터넷','description':'여행자료','source_slug':'_ 1','subject_name':'여행','subject_slug':'_ 6'}] < / p>
我想将source_name“인터넷”的值放到source_name变量中。 我想在这一行使用soure_name变量。
public double totalAssets(){
double sum = 0.0;
for (int i=0; i<warehouseRacks.length; i++){
for (int j=0; j<warehouseRacks[i].length; j++){
Rack racks = warehouseRacks[i][j];
Item[] item = racks[i].getItem();
sum = sum + thing[j].getPrice();
}
}
return sum;
}
但是source_name未定义。 请帮帮我
这是代码。
html += '<li><span> 출처 : <a href="/tag/' + source_slug + '">' + source_name + '</a>'
答案 0 :(得分:0)
您需要在以下内容之后进行更改:
function showModal(){
var pk = $(this).find('img').attr('id');
$.ajax({
url : '/photo/' + pk + '/',
async: false,
success: function(data){
data= JSON.stringify(data)
var source_slug = data[0]["source_slug"];
var source_name = data[0]["source_name"];
var description = data[0]["description"];
var subject_slug = data[0]["subject_slug"];
var subject_name = data[0]["subject_name"];
var src = $(this).find('img').attr('src');
var largeImg = $(this).find('img').attr('data-bsp-large-src');
if(typeof largeImg === 'string'){
src = largeImg;
}
var index = $(this).attr('data-bsp-li-index');
var ulIndex = $(this).parent('ul').attr('data-bsp-ul-index');
var ulId = $(this).parent('ul').attr('data-bsp-ul-id');
var theImg = $(this).find('img');
var pText = $(this).find('.text').html();
var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;
clicked.img = src;
clicked.prevImg = parseInt(index) - parseInt(1);
clicked.nextImg = parseInt(index) + parseInt(1);
clicked.ulIndex = ulIndex;
clicked.ulId = ulId;
$('#bsPhotoGalleryModal').modal();
var html = '';
var img = '<img src="' + clicked.img + '" class="img-responsive"/>';
html += img;
html += '<span class="' + settings.iconClose + ' bsp-close"></span>';
html += '<div class="bsp-text-container">';
html += '<li><span> 출처 : <a href="/tag/' + source_slug + '">' + source_name + '</a>'
html += '</span></li>'
html += '<li><span> 과목 및 단원 :<a href="/tag/' + subject_slug + '">' + subject_name + '</a>'
html += '<li><span>' + description + '</span></li>'
html += '</div>';
html += '<a class="bsp-controls next" data-bsp-id="'+clicked.ulId+'" href="'+ (clicked.nextImg) + '"><span class="' + settings.iconRight + '"></span></a>';
html += '<a class="bsp-controls previous" data-bsp-id="'+clicked.ulId+'" href="' + (clicked.prevImg) + '"><span class="' + settings.iconLeft + '"></span></a>';
$('#bsPhotoGalleryModal .modal-body').html(html);
$('.bsp-close').on('click', closeModal);
showHideControls();
}
});}