我正在Videos.find(...)
使用console.log()
和console.log()
。我试图让videos
函数返回一个按其'index'字段排序的数组。请参阅下面的代码。
第一个export default DashboardContainer = createContainer(props => {
const videosHandle = Meteor.subscribe('userVideos');
const loading = !videosHandle.ready();
const videos = !loading ? Videos.find({}, {fields: {title:1, subtitle:1,
duration:1, thumb:1, url:1, index:1, groups:1}, sort: {index:1}}).fetch() : [];
// logs the array properly sorted by the index field of the elements
console.log(Videos.find({}, {fields: {title:1, subtitle:1, duration:1, thumb:1, url:1, index:1, groups:1}, sort: {index:1}}).fetch());
// logs the array unsorted (unwanted behaviour)
console.log(videos);
return {
loading,
videos,
};
}, Dashboard);
打印正确排序的数组。第二个console.log(videos.map((i) => i.index));
以默认顺序打印数组。即使我更改排序选项,它似乎也被忽略了。我无法弄清楚如何将console.log(videos)
常数排序。
[1,2,3,4,5...]
如果我使用 <?php
$max_columns = 3; //columns will arrange to any number (as long as it is evenly divisible by 12)
$column = 12/$max_columns; //column number
$total_items = count( get_field('services_services'));
$remainder = $total_items%$max_columns; //how many items are in the last row
$first_row_item = ($total_items - $remainder); //first item in the last row
?>
<?php $i=0; // counter ?>
<?php while ( have_rows('services_services') ) : the_row(); ?>
<?php if ($i%$max_columns==0) { // if counter is multiple of 3 ?>
<div class="row">
<?php } ?>
<?php if ($i >= $first_row_item) { //if in last row ?>
<div class="col-md-<?php echo 12/$remainder; ?>">
<?php } else { ?>
<div class="col-md-<?php echo $column; ?>">
<?php } ?>
<div class="service-box">
<h3 class="service-heading"><?php echo the_sub_field('service_name'); ?></h3>
<span class="<?php echo the_sub_field('service_fa_class'); ?>" aria-hidden="true"></span>
<p class="heading-text"><?php echo the_sub_field('service_description'); ?></p>
<a href="<?php echo the_sub_field('service_learn_more_url'); ?>" class="btn btn-info">Learn More</a>
</div>
</div>
<?php $i++; ?>
<?php if($i%$max_columns==0) { // if counter is multiple of 3 ?>
</div>
<?php } ?>
<?php endwhile; ?>
<?php if($i%$max_columns!=0) { // put closing div if loop is not exactly a multiple of 3 ?>
</div>
<?php } ?>
代替from()
,我会按正确顺序打印列表:
join()
为什么?!