我有10个项目的数组,每个项目都有自己的价格。
我必须选择一些项目并显示所选项目的平均值,如果任何所选项目高于平均值,我必须在每个单元格的2x2表格不同图片中显示它的图片。
我写这段代码,但问题是4个单元格中的pic重复:
public interface IIncrementalSource<T>
{
Task<IEnumerable<T>> GetPagedItems(int pageIndex, int pageSize);
}
public class IncrementalLoadingCollection<T, I> : ObservableCollection<I>,
ISupportIncrementalLoading
where T : IIncrementalSource<I>, new()
{
private T source;
private int itemsPerPage;
private bool hasMoreItems;
private int currentPage;
public IncrementalLoadingCollection(int itemsPerPage = 20)
{
this.source = new T();
this.itemsPerPage = itemsPerPage;
this.hasMoreItems = true;
}
public bool HasMoreItems
{
get { return hasMoreItems; }
}
public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
{
var dispatcher = Window.Current.Dispatcher;
return Task.Run<LoadMoreItemsResult>(
async () =>
{
uint resultCount = 0;
var result = await source.GetPagedItems(currentPage++, itemsPerPage);
if (result == null || result.Count() == 0)
{
hasMoreItems = false;
}
else
{
resultCount = (uint)result.Count();
await dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() =>
{
foreach (I item in result)
this.Add(item);
});
}
return new LoadMoreItemsResult() { Count = resultCount };
}).AsAsyncOperation<LoadMoreItemsResult>();
}
}
答案 0 :(得分:0)
首先你必须创建图像数组,因为如果你将以这种方式显示并且某些项目与条件不匹配,那么它将留空<td>
解决方案:
<?php
echo "<table border=2>";
$incVar = 0;
for ($x = 0; $x < 2; $x++) {
echo"<tr>";
for ($y = 0; $y < 2; $y++) {
echo"<td>";
if (isset($camera[$incVar]) && $camera[$incVar] >= $avreag) {
echo '<img src="' . $pic[$incVar] . '" width="200" height="200">';
}
$incVar++;
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
不需要在4x4 for loop
中显示$imagesArr