在服务器上运行以下Router类:
var PetsRouterBase = Router.createClass([{
route: 'petList[{integers:indices}].name',
get: function(pathSet) {
return [
{
path: ['petList', 0, 'name'],
value: 'Pets I have now'
},
{
path: ['petList', 1, 'name'],
value: 'Pets I once had'
},
{
path: ['petList', 2, 'name'],
value: 'Pets my friends have'
}
];
}
}]);
浏览器中的以下路径查询(我使用的是falcor-http-datasource):
model.get('petList[0..2].name');
我得到了正确的数据:
{
"jsonGraph": {
"petList": {
"0":{"name":"Shows of Artists I've been to before",
"1":{"name":"Shows of artists my friends have been to before",
"2":{"name":"Highly rated artists"}
}
}
}
我的问题是,在服务器上,是一种让我可以访问falcor通过线路发送回浏览器以响应此获取路由请求的实际结果的方法吗?
我的用例是我想要将两个数据一起注销:
我原以为它可能看起来像这样:
var PetsRouterBase = Router.createClass([{
route: 'petList[{integers:indices}].name',
done: function(pathSet, results) {
// Log out the result of the lookup
console.log(pathSet, results);
},
get: function(pathSet) {
return [
{
path: ['petList', 0, 'name'],
value: 'Pets I have now'
},
{
path: ['petList', 1, 'name'],
value: 'Pets I once had'
},
{
path: ['petList', 2, 'name'],
value: 'Pets my friends have'
}
];
}
}]);
要清楚。我知道我可以在客户端获得结果,但我想将它们传输到服务器上的其他地方。
答案 0 :(得分:1)
目前最简单的事情就是在将路由器发送到快速中间件之前对其进行装饰。
app.use('/model.json', FalcorServer.dataSourceRoute(function(req, res) {
return {
get: function(pathSets) {
// print incoming paths to console
console.log(JSON.stringify(pathSets, null, 4));
return router.
get(pathSets).
// print the results to the console
doAction(function(output) {
console.log(JSON.stringify(output, null, 4));
});
}
};
})