ページの読み込み時に要素のリストをレンダリングする React.js コンポーネントがありますが、このリストは、リストから特定の要素を削除し、変更されたリストをコンポーネントの状態で保存するフィルターで更新できます。この機能を機能させることができたので、状態は正しく更新されます。
要素は正しく再レンダリングされますが、レンダリングされる要素が少ないほど、使用されるスペースは少なくなります。これが発生すると、ページが占有する新しいサイズに合わせてページの高さが縮小されず、ページの最後の要素であるフッターの下に空のコンテンツが残ります。
編集 :
これをもう少し詳しく調べたところ、React.js が問題の原因ではない可能性があると思います。コンポーネントの状態が更新されるたびに imagesLoaded および Wookmark jQuery プラグインを使用する関数を呼び出しますが、状態が変化するたびにこの関数を呼び出すとうまくいきません。呼び出された関数を変更する必要があるか、別の時点で関数を呼び出す必要がありますか?
var ActivityListClass = React.createClass({
loggedInUser: {},
componentDidUpdate: function() {
activityListImageResponsiveness(); // This is the function
},
componentDidMount: function() {
var theActivityList = this;
var activitiesGetListener = postal.subscribe({
channel: "activities",
topic: "list",
callback: function(data, envelope) {
var dataClone = $.extend(true, {}, data);
dataClone.activities.shift();
theActivityList.setState({data: dataClone.activities});
theActivityList.loggedInUser = dataClone.loggedInUser;
}
});
},
getInitialState: function() {
return {data: []};
},
render: function() {
var i = 0;
var activityNodes = this.state.data.map(function(activity) {
var currentId = i;
i++;
return (
<ActivityClass key={currentId} data={activity} />
);
});
return (
<section id="listArticles">
{activityNodes}
</section>
);
}
});
呼び出される関数は次のように定義されます。
function activityListImageResponsiveness() {
$('#listArticles').imagesLoaded(function() {
// Get a reference to your grid items.
var $handler = $('#listArticles article');
$handler.on("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", function(event) {
if(event.originalEvent.propertyName == 'top'){
$('#listArticles').trigger("refreshWookmark");
}
});
// Prepare layout options.
var options = {
align: 'left',
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $('#listArticles'), // Optional, used for some extra CSS styling
direction: 'left',
fillEmptySpace: true, // Optional, fill the bottom of each column with widths of flexible height
flexibleWidth: '16.635%',
itemWidth: $handler.width(), // Optional, the width of a grid item
offset: 42, // Optional, the distance between grid items
verticalOffset: 15
};
var $window = $(window);
$window.resize(function() {
var windowWidth = $window.width(),
newOptions = {
flexibleWidth: '16.635%',
itemWidth: 208
};
// NOTE: These values are the same as the "media queries" of the CSS file.
if(windowWidth >= 1263){
newOptions.flexibleWidth = '16.635%';
newOptions.itemWidth = 208;
} else if (windowWidth >= 1132){
newOptions.flexibleWidth = '21.05263157894737%';
newOptions.itemWidth = 236;
}else if(windowWidth >= 1014){
newOptions.flexibleWidth = '20.71713147410359%';
newOptions.itemWidth = 208;
}else if(windowWidth >= 852){
newOptions.flexibleWidth = '27.99525504151839%';
newOptions.itemWidth = 236;
}else if(windowWidth >= 764){
newOptions.flexibleWidth = '27.51322751322751%';
newOptions.itemWidth = 208;
}else if(windowWidth >= 626){
newOptions.flexibleWidth = '42.58064516129032%';
newOptions.itemWidth = 264;
}else if(windowWidth >= 515){
newOptions.flexibleWidth = '40.7843137254902%';
newOptions.itemWidth = 208;
}else{
newOptions.flexibleWidth = '83.80952380952381%';
newOptions.itemWidth = 264;
}
$handler.wookmark(newOptions);
});
// Call the layout function.
$handler.wookmark(options);
});
}