简介
这里是我学习meteor,react
及其相关技术的一些代码片段和总结,持续更新...
arrow function
箭头函数的使用方法:
- 使用大括号,里面必须有
return
语句 - 使用括号,里面不用
return
关键字,易读 - 不使用括号,适用于返回一条语句,不易读
1 |
Meteor.publish('posts.all', function() { |
mongo数据库链式操作
数据库结构:
- title —>string
- contents —>array
- name —>string
- read —>boolean
- …
- createdAt —> date
- …
需要传递的参数:
- title —>string
- contentName —> string
- read —>boolean
以下表示:找出标题为title
,且内容的名字叫contentName
的文章,并把它的内容中的已读值设置为read
1 |
Posts.update( |
react dangerouslySetInnerHTML
注意大括号,接受object
1 |
<div dangerouslySetInnerHTML={{ __html: content }}> |
react组件生命周期函数
上传并显示图片时,如果离开页面,然后再次返回,还会显示上次上传的图片,需要调用react
的生命周期函数.
1 |
componentWillMount() { |
大专栏 使用meteor/react过程中的一些代码片段headerlink" title="summernote编辑器显示内容">summernote编辑器显示内容
让编辑器初始化时就显示传入的一些内容,比如一个html中的section内容
1 |
//最外层包裹编辑器,并通过dangerouslySetInnerHTML渲染html内容 |
summernote编辑器的api调用
假如我们希望点击显示或隐藏按钮后,编辑器能够动态显示,而不刷新整个页面,需要如下操作
1 |
//进入页面后,初始化编辑器 |
lodash中sortBy进行数组排序
比如一篇文章有很多评论,需要根据评论数目进行排序,我们可以直接返回排序过的数组.
1 |
const singlePost = Posts.findOne(); |