我正在学习一个名为 admin bro 的后端管理仪表板框架。所以基本上我正在尝试制作一个工具提示组件。这是我到目前为止尝试过的代码。
class Textbox extends React.PureComponent {
render() {
const { property } = this.props;
const ob = this.props.property.name
const sentence = {
first : ' this is the first text ',
second : ' this is second text',
third: 'this is third text',
fourth : 'this is the fourth text',
}
var line = sentence[ob]
return (
<script type="text/javascript">
document.write(line)
</script>
)
}
}
export default withTheme(Textbox)
Run Code Online (Sandbox Code Playgroud)
其中ob有第一、第二、第三和第四等值,因此当它是时,sentence[ob]它意味着例如句子[first](当ob是第一个时),line然后获取相应的文本,即“这是第一个文本”。我已经安慰记录line并看到这部分工作完美。
现在我只需要 …
我有一个这样的获取 API
router.get('/exist', async (req, res) => {
try {
const { user: { _id: userId } } = req;
const user = await User.findById(userId);
const profile = await Profile.findById(user.profile, 'role admin');
const admin = await Admin.findOne({ _id: profile.admin })
res.send(admin.role,profile);
} catch (e) {
res.status(500).send();
}
});
Run Code Online (Sandbox Code Playgroud)
在admin只有一个领域一个要发送回叫的作用。这就是为什么在 res.send() 我写了admin.role.
所以基本上我想这两个领域发回一起admin.role和profile。
直到现在我已经尝试与合并
Object.assign(profile,admin)
Run Code Online (Sandbox Code Playgroud)
&
{...profile,...admin}
Run Code Online (Sandbox Code Playgroud)
这两个都不起作用。
我该怎么做呢?