現在、{post.htmlBody} は個々の投稿ページに表示されますが、投稿リスト ビューには表示されません。最初のコード ブロックは私の CustomPostsItem.jsx です。上部に定義されている {post.htmlBody} を表示しようとしている h3 タグの下に表示されます。PostsList.jsx である 2 番目のコード ブロック内で CustomPostsItem.jsx が呼び出された場合、これは読み込まれません。PostsPage.jsx である 3 番目のコード ブロック内で CustomPostsItem.jsx が呼び出されると、適切に入力されて表示されます。つまり、ホームページには表示されませんが、同じ CustomPostsItem.jsx が両方とも呼び出されていても、個々の投稿ページに表示されます。また、htmlBody の代わりに {post.body} だけを試してみましたが、同じことが起こります。
import React, { PropTypes, Component } from 'react';
class CustomPostsItem extends Telescope.components.PostsItem {
render() {
({UsersAvatar, UsersName, Vote, PostsStats, PostsThumbnail} = Telescope.components);
const post = this.props.post;
const htmlBody = {__html: post.htmlBody};
let postClass = "posts-item";
if (post.sticky) postClass += " post-sticky";
// ⭐ custom code starts here ⭐
if (post.color) {
postClass += " post-"+post.color;
}
// ⭐ custom code ends here ⭐
return (
<div className={postClass}>
<div className="posts-item-vote">
<Vote post={post} currentUser={this.props.currentUser}/>
</div>
{/*post.thumbnailUrl ? <PostsThumbnail post={post}/> : null*/}
<div className="posts-item-content">
<h3 className="posts-item-title">
<a className="posts-item-title-link" href={Posts.getLink(post)} target={Posts.getLinkTarget(post)}>{post.title}</a>
{this.renderCategories()}
</h3>
<div className="posts-page-body" dangerouslySetInnerHTML={htmlBody}></div>
</div>
</div>
)
}
};
export default CustomPostsItem;
import React from 'react';
const PostsList = ({results, currentUser, hasMore, ready, count, totalCount, loadMore, showHeader = true}) => {
// console.log(results);
// console.log(ready);
// console.log(hasMore);
// console.log(totalCount);
// console.log(count);
if (!!results.length) {
return (
<div className="posts-list">
{showHeader ? <Telescope.components.PostsListHeader /> : null}
<div className="posts-list-content">
{results.map(post => <Telescope.components.PostsItem post={post} currentUser={currentUser} key={post._id}/>)}
</div>
{hasMore ? (ready ? <Telescope.components.PostsLoadMore loadMore={loadMore} count={count} totalCount={totalCount} /> : <Telescope.components.PostsLoading/>) : <Telescope.components.PostsNoMore/>}
</div>
)
} else if (!ready) {
return (
<div className="posts-list">
{showHeader ? <Telescope.components.PostsListHeader /> : null}
<div className="posts-list-content">
<Telescope.components.PostsLoading/>
</div>
</div>
)
} else {
return (
<div className="posts-list">
{showHeader ? <Telescope.components.PostsListHeader /> : null}
<div className="posts-list-content">
<Telescope.components.PostsNoResults/>
</div>
</div>
)
}
};
PostsList.displayName = "PostsList";
module.exports = PostsList;
import React from 'react';
const PostsPage = ({document, currentUser}) => {
const post = document;
const htmlBody = {__html: post.htmlBody};
return (
<div className="posts-page">
<Telescope.components.HeadTags url={Posts.getLink(post)} title={post.title} image={post.thumbnailUrl} />
<Telescope.components.PostsItem post={post}/>
<div className="posts-page-body" dangerouslySetInnerHTML={htmlBody}></div>
{/*<SocialShare url={ Posts.getLink(post) } title={ post.title }/>*/}
<Telescope.components.PostsCommentsThread document={post} currentUser={currentUser}/>
</div>
)
};
PostsPage.displayName = "PostsPage";
module.exports = PostsPage;
export default PostsPage;