MineR

牵手生命线就交错

在《Discover Meteor》书中249页有错误

18 June 2014

Meteor是一个优秀的框架,《Discover Meteor》是一本优秀的入门书籍。只是在249页的代码中有一个逻辑bug,原文如下:

//..
	attributes: function() {
		var post = _.extend({}, Positions.findOne({postId: this._id}), this); var newPosition = post._rank * POST_HEIGHT;
		var attributes = {};
		if (_.isUndefined(post.position)) { 
			attributes.class = 'post invisible';
		} else {
			var delta = post.position - newPosition; 
			attributes.style = "top: " + delta + "px";
			if (delta === 0)
				attributes.class = "post animate" 
		}
		Meteor.setTimeout(function() {
			Positions.upsert(
				{postId: post._id},
				{$set: {position: newPosition}}
			)
		});
		return attributes; 
	}
	//..

/client/views/posts/post_item.js

如果使用了这段代码,那么页面上的post就全部消失了,因为代码将所有attributes.class都预设为‘post invisible’。这里需要调换if-else区块内的代码,变成如下即可恢复正常:

//..
	attributes: function() {
		var post = _.extend({}, Positions.findOne({postId: this._id}), this); var newPosition = post._rank * POST_HEIGHT;
		var attributes = {};
		if (_.isUndefined(post.position)) { 
			var delta = post.position - newPosition; 
			attributes.style = "top: " + delta + "px";
			if (delta === 0)
				attributes.class = "post animate" 

		} else {
			attributes.class = 'post invisible';
		}
		Meteor.setTimeout(function() {
			Positions.upsert(
				{postId: post._id},
				{$set: {position: newPosition}}
			)
		});
		return attributes; 
	}
	//..

/client/views/posts/post_item.js

在家用路由器内网搭建可以互联网访问的服务器

1. 将一台废旧的电脑安装linux系统(我安装了ubuntu 32位 16.04),变成一台服务器2. 用网线连接上内网路由器,并且绑定内网IP地址3. 设置DMZ将外网访问转发到服务器4. 注册一个DDNS服务,并且申请一个域名5. 将域名和账号填入路由器设置里(我家用...… Continue reading

爱在时间里

Published on December 11, 2015