Angularjs 在用“创建的项目中”;发电机角度全堆叠“;,如何筛选列表项(在服务器端)?
我正在使用: 已使用以下设置创建项目: 开箱即用,我创建了一个带有Express服务器的AngularJS应用程序 客户 ??您想用什么编写标记HTML ? 您想用什么编写样式表CSS ? 您想使用什么角度路由器ui路由器 ? 您想包括引导吗是 ? 是否要包括UI引导是 服务器 ??您希望使用什么进行数据建模猫鼬(MongoDB) ? 你能拿出一个认证样板吗是 ? 您想包括其他oAuth策略吗Facebook、Twitter ? 是否要使用socket.io是 项目 ??您想用什么编写测试?(使用箭头键)茉莉花 我创建了新的端点“保留”: 更新了新页面中填充的“保留”列表。 但它得到了所有的“预订”项目 我想在用户登录时获得所有预订。 在其他情况下(非用户或简单用户),我只想获得活动预订。 因此有一种简单的预订模式:Angularjs 在用“创建的项目中”;发电机角度全堆叠“;,如何筛选列表项(在服务器端)?,angularjs,mongodb,bluebird,angular-fullstack,Angularjs,Mongodb,Bluebird,Angular Fullstack,我正在使用: 已使用以下设置创建项目: 开箱即用,我创建了一个带有Express服务器的AngularJS应用程序 客户 ??您想用什么编写标记HTML ? 您想用什么编写样式表CSS ? 您想使用什么角度路由器ui路由器 ? 您想包括引导吗是 ? 是否要包括UI引导是 服务器 ??您希望使用什么进行数据建模猫鼬(MongoDB) ? 你能拿出一个认证样板吗是 ? 您想包括其他oAuth策略吗Facebook、Twitter ? 是否要使用socket.io是 项目 ??您想用什么编写测试?(使
var ReservationSchema = new Schema({
date: {
type: Date,
required: true
}
//,user: {
// type : Schema.ObjectId,
// ref : 'User'
//}
});
当“新日期()”// Gets a list of Active Reservations
export function active(req, res) {
Reservation.findActive()
.execAsync()
.then(responseWithResult(res))
.catch(handleError(res));
}
这些方法如下所示:
// Gets a list of Reservations
export function index(req, res) {
Reservation.findAsync()
.then(responseWithResult(res))
.catch(handleError(res));
}
因此,我为ActiveReservations创建了另一个函数:
yo angular-fullstack:endpoint reservation //Server side
yo angular-fullstack:route reservatios //Client Route
// Gets a list of Active Reservations
export function active(req, res) {
Reservation.findAsync()
.then(getOnlyActive(res))
.then(responseWithResult(res))
.catch(handleError(res));
}
所以我添加了这个自定义函数“getOnlyActive(res)”
我的问题:
该函数中应该包含什么,如何过滤“res”,以仅获取活动预订?我认为应该在这里进行过滤。更正“我的”并指向“正确批准”如何从mongoDB(使用mongoose)获取筛选项目。最后了解如何进行筛选:) 在示例中,这是我的模型(server\api\reservation\reservation.model.js): 我在其中添加了新的静态函数:
ReservationSchema.statics.findActive = function (next) {
return this.find({"date": {"$gte": new Date()}});
};
然后将新函数添加到保留控制器(server\api\reservation\reservation.controller.js)
最后添加了活动预订的路由(server\api\reservation\index.js):
现在它工作了:)。通过调用浏览器进行检查:
//获取所有预订
//仅获取活动预订-使用的是“reservation.date>new date()”您应该真正阅读文档:因此我对这些查询的理解是蓝鸟promisive样式:var mongoose=require('bluebird')。promisifyAll(require('mongoose'));我是mongodb和这只蓝鸟的新手。因此,在书面案例中获得如何进行过滤的完整示例是很好的。谢谢
ReservationSchema.statics.findActive = function (next) {
return this.find({"date": {"$gte": new Date()}});
};
// Gets a list of Active Reservations
export function active(req, res) {
Reservation.findActive()
.execAsync()
.then(responseWithResult(res))
.catch(handleError(res));
}
router.get('/active', controller.active);