Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 串联并行数组Jquery_Php_Jquery_Html_Arrays_Json - Fatal编程技术网

Php 串联并行数组Jquery

Php 串联并行数组Jquery,php,jquery,html,arrays,json,Php,Jquery,Html,Arrays,Json,基本上与问题相同,但是使用jQuery来组合html页面 我有一组三个平行的对象和数组。(可以成为二维阵列) 在我的一生中,我无法想象如何让它们在没有相互碰撞的情况下填充我的页面 因此,我可以存储$中的数据。每个函数如下: $.ajax({ url: 'populate.php', dataType: 'json', async: false, data: "{'images','links','projects'}", success: function(data, object) {

基本上与问题相同,但是使用jQuery来组合html页面

我有一组三个平行的对象和数组。(可以成为二维阵列)

在我的一生中,我无法想象如何让它们在没有相互碰撞的情况下填充我的页面

因此,我可以存储$中的数据。每个函数如下:

$.ajax({
url: 'populate.php',
dataType: 'json',
async: false,
data: "{'images','links','projects'}",
success: function(data, object) {
   $.each(data.images, function(index, value) {
      // maybe something like?: $images = $('.footer').prepend('<img src="'+value+'" />')
   });
   $.each(data.links, function(index, value) {
      $('.footer').prepend('<a>'+value+'</a>')
   });
   $.each(data.projects, function(index, value) {
      $('.footer').prepend('<a>'+value+'</a>')
   });
   }
});
});
$.ajax({
url:'populate.php',
数据类型:“json”,
async:false,
数据:“{'images','links','projects'}”,
成功:函数(数据、对象){
$.each(数据、图像、函数(索引、值){
//可能类似于?:$images=$('.footer')。前置(''')
});
$.each(数据链接、函数(索引、值){
$('.footer').prepend(''+data.projects+'');
还是我想做的完全错了


谢谢!

您在循环中构建标记,使用索引访问与当前迭代数组相对应的数组值,并在构建完成后将其插入DOM中

var html = $([]);

$.each(data.images, function(index, value) {
  var wrap  = $('<div />', {'class' : 'wrap'}),
      box   = $('<div />', {'class' : 'box'}),
      inner = $('<div />', {'class' : 'boxInner'}),
      a     = $('<a />',   {href : data.links[index]}),
      img   = $('<img />', {src : value}),
      title = $('<div />', {'class' : 'titleBox', text : data.projects[index]});

  html = html.add(wrap.append(box.append(boxInner.append(a.append(img), title))));
});

$('body').append(html);
var html=$([]);
$.each(数据、图像、函数(索引、值){
var wrap=$('',{'class':'wrap'}),
box=$('',{'class':'box'}),
内部=$('',{'class':'boxInner'}),
a=$('',{href:data.links[index]}),
img=$(“”,{'class':'titleBox',text:data.projects[index]});
html=html.add(wrap.append(box.append(boxInner.append)(a.append(img),title));
});
$('body').append(html);

我可以吻你!太棒了!
$('body').append('<div class="wrap"><div class="box"><div class="boxInner"><a href="'+data.links+'"><img src="'+data.images+'"/></a><div class="titleBox">'+data.projects+'</div></div></div>');
var html = $([]);

$.each(data.images, function(index, value) {
  var wrap  = $('<div />', {'class' : 'wrap'}),
      box   = $('<div />', {'class' : 'box'}),
      inner = $('<div />', {'class' : 'boxInner'}),
      a     = $('<a />',   {href : data.links[index]}),
      img   = $('<img />', {src : value}),
      title = $('<div />', {'class' : 'titleBox', text : data.projects[index]});

  html = html.add(wrap.append(box.append(boxInner.append(a.append(img), title))));
});

$('body').append(html);