【问题标题】:meanjs route to server controllermeanjs 路由到服务器控制器
【发布时间】:2015-02-19 21:08:29
【问题描述】:

我正在尝试向我的控制器“matches.server.controller”名称列表团队添加一个新方法。 我已经向 matchs.server.route.js 文件添加了一条新路由,如下所示

'use strict';

/**
 * Module dependencies.
 */
var users = require('../../app/controllers/users.server.controller'),
matches = require('../../app/controllers/matches.server.controller');

module.exports = function(app) {
// Match Routes
app.route('/matches/listTeams')                 <-- new route added here !!
    .get(matches.listteams);


app.route('/matches')
    .get(matches.list)
    .post(users.requiresLogin, matches.create);


app.route('/matches/:matchId')
    .get(matches.read)
    .put(users.requiresLogin, matches.hasAuthorization, matches.update)
    .delete(users.requiresLogin, matches.hasAuthorization, matches.delete);

// Finish by binding the matches middleware
app.param('matchId', matches.matchByID);
};

这是我的服务器控制器中的方法:

exports.listteams = function(req, res) {
    res.json(1);
};

在matches.client.controller 我这样调用方法:

 $scope.listteams = function(){
        $scope.teams = Matches.get('matches/listTeams').success(function(data){
            var d = data;
        }).error(function(data){
            var d = data;
        });

但是,当我调试时,我总是在匹配的列表方法中而不是在 listTeams 方法中 我做错了什么?

【问题讨论】:

  • 据我所知您使用的是meanjs.org
  • 你为什么把这个控制器搞砸了?接收来自 MongoDB 的团队数组?
  • 我“搞砸这个控制器”的原因是因为团队不在 mongodb 中,但我想从 Web 服务中获取它们。

标签: angularjs node.js express meanjs


【解决方案1】:

可能是因为你复制了路径名

'/matches/' 之后的所有参数都被处理

app.route('/matches/:matchId')
    .get(matches.read)
    .put(users.requiresLogin, matches.hasAuthorization, matches.update)
    .delete(users.requiresLogin, matches.hasAuthorization, matches.delete);

并感知'/:matchId'的类似论点

在你的情况下:find me team with id "listTeams"

尝试将您的路径从 matches 重命名为其他类似

module.exports = function(app) {
// Match Routes
app.route('/smthelse_not_matches/listTeams')   <-- new route added here !!
    .get(matches.listteams);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2015-02-14
    • 1970-01-01
    相关资源
    最近更新 更多