我有一组数组,当被调用php到javascript数据元素时,看起来如下所示。
for($index =0; $index < 100; $index++
data-example2 = "'htmlspecialchars(json_encode($ExampleArray[$index][28]), ENT_Quotes, 'CP1252')
...
&#34; $ ExampleArray [$指数] [28]&#34; - 返回
Array (
[0] => Example Text 1
)
Array (
[0] => Example Text 2
[1] => Example Text 3
[2] => Example Text 4
[3] => Example Text 5
)
Array (
[0] => Example Text 6
[1] => Example Text 7
)
等等等
传递了四个数据条目,例如
$ExampleArray[$index][28], $ExampleArray[$index][29], $ExampleArray[$index][30], $ExampleArray[$index][31]
他们的值条目与彼此匹配。例如
$ ExampleArray [$ index] [28],第一个数组[0]与
匹配$ ExampleArray [$ index] [29] array [0],
$ ExampleArray [$ index] [30] array [0],
$ ExampleArray [$ index] [31] array [0],
在我的java脚本中,我为每个ex ...设置变量
$exOne = $(this).data("example");
$exTwo = $(this).data("example2");
$exThree = $(this).data("example3");
$exFour = $(this).data("example4");
exOne是日期,所以我有一个排序功能,可以列出从最新到最旧的
$exTwo = $exTwo.sort().reverse();
然后我使用一个函数来帮助将这些数据放入表中
$exOne.forEach(function(value, key){
let firstExample = $exOne[key],
secondExample = $exTwo[key]?$exTwo[key]:"",
thirdExample = $exThree[key]?$exThree[key]:"",
fourthExample = $exFour[key]?$exFour[key]:"";
问题是当我订购exOne(数组中充满了日期)时,它会混淆所有其他数据的匹配。如果我没有订购exOne,一切都完美对齐。
我也做了
console.log(secondExample的类型)*其他的以及它们都是字符串类型。