2016-07-26 97 views
3

未來我有一個問題,使這個URL路徑:快速路由使用參數過濾器從emberJs

http://localhost:3000/api/tests?filter%5Bcodeid%5D=eeee

在我想這一刻:

在服務器

app.route('/api/tests?filter[codeid]=:param') 
    .get((req, res) => { 
    console.log('It works'); 
    res.status(200).send({ 
     msg: 'It works' 
    }); 
    }); 

在前面

this.store.query('test', { filter: { codeid: code } }) 
    .then(test => { 
     if(test.get('firstObject')){ 
     console.log(test.get('firstObject').get('id')); 
     console.log('exist'); 
     } 
    }) 
    .catch(err => { 
     console.log(err); 
    }); 

但是當我測試服務器郵遞員我有這樣的結果:

Cannot GET /api/tests?filter%5Bcodeid%5D=eeee

有人對如何管理這個任何想法?

編輯:

我使用JSON-API

https://github.com/ethanresnick/json-api

這是我的所有路由我的服務器上的文件:下面

https://github.com/DidelotK/QcmServerEmber/blob/Express_problem_stack/app/controller/express-server.js

+0

綁定路徑是'/ api/tests','?filter%5Bcodeid%5D = eeee'是請求參數。你可以綁定'/ api/test/filter-:codeid'。 –

+0

相同的東西它不起作用 –

回答

0

我終於找到解決辦法我的問題,在這裏:

https://github.com/ethanresnick/json-api/issues/64

所以誤差在燼,並使其工作,我改變了這一點:

this.store.query('test', { filter: { codeid: code } }) 
.then(test => { 
    if(test.get('firstObject')){ 
    console.log(test.get('firstObject').get('id')); 
    console.log('exist'); 
    } 
}) 
.catch(err => { 
    console.log(err); 
}); 

要這樣:

this.store.query('test', { filter: { simple { codeid: code } } }) 
.then(test => { 
    if(test.get('firstObject')){ 
    console.log(test.get('firstObject').get('id')); 
    console.log('exist'); 
    } 
}) 
.catch(err => { 
    console.log(err); 
}); 
-1

try代碼

var express = require('express'); 
var app = express(); 
app.use(require('body-parser').urlencoded({extended: false})); // to provide req.params.param 

app.route('/test') 
    .get((req, res) => { 
    console.log('It works'); 
    res.status(200).json({ // I think you doesn't want send text 
     msg: 'It works' 
    }); 
    }); 

app.route('/test/filter[codeid]=:param') 
    .get((req, res) => { 
    console.log('It works', req.params.param); 
    res.status(200).send({ 
     msg: 'It works', 
     code: req.params.param 
    }); 
    }); 

app.listen(3000, function() { 
    console.log('Example app listening on port 3000!'); 
}); 
+0

相同的事情過濾器不起作用,我只有它的作品 –

2

什麼你正在試圖做的是叫快遞查詢,Express doc,所以你的路線不應該有額外的參數,它應該是這個樣子

app.get('/test', (req, res, next) => { 
    console.log(req.query); 
    res.status(200).json(req.query);  
}); 

而當u對這條路不是發送請求..

http://localhost:3000/test?a=5&b=3