在通过从mongoose中获取数据连接的angularjs中自动完成
嘿家伙 ,
我正在调查Angularjs中的自动完成字段,它从mongoose获取数据…这样的东西https://stackoverflow.com/questions/18460374/angularjs-autocomplete-from-http但事情是我dint理解正确…如果你们帮我简单的例子,它会很高兴!
提前致谢!!!
$(function () { $("#search-query").autocomplete({<br> source: function (request, response) {<br> $.ajax({<br> url: "/search_member",<br> type: "GET",<br> data: request, // request is the value of search input<br> success: function (data) {<br> // Map response values to fiedl label and value<br> response($.map(data, function (el) {<br> return {<br> label: el.fullname,<br> value: el._id<br> };<br> }));<br> }<br> });<br> }, <br> minLength: 3, <br> focus: function (event, ui) {<br> this.value = ui.item.label;<br> // Prevent other event from not being execute<br> event.preventDefault();<br> },<br> select: function (event, ui) {<br> // Prevent value from being put in the input:<br> this.value = ui.item.label;<br> // Set the id to the next input hidden field<br> $(this).next("input").val(ui.item.value);<br> // Prevent other event from not being execute <br> event.preventDefault();<br> // optionnal: submit the form after field has been filled up<br> $('#quicksearch').submit();<br> }<br> });<br> });<br>
服务器端编码
<br> User = mongoose.model('User'); // Declare a new mongoose User <br> app.get('/search_member', function(req, res) {<br> var regex = new RegExp(req.query["term"], 'i');<br> var query = User.find({fullname: regex}, { 'fullname': 1 <br>}).sort({"updated_at":-1}).sort({"created_at":-1}).limit(20);<br> // Execute query in a callback and return users list<br> query.exec(function(err, users) {<br> if (!err) {<br> // Method to construct the json result set<br> var result = buildResultSet(users);<br> res.send(result, {<br> 'Content-Type': 'application/json'<br> }, 200);<br> } else {<br> res.send(JSON.stringify(err), {<br> 'Content-Type': 'application/json'<br> }, 404);<br> }<br> });<br> });<br>
- 明确存在的function被确定为未定义的
- 如何将MEAN堆栈部署到我的托pipe服务器?
- MEAN应用程序中的项目单独页面
- 用Angular,Express和Jade刷新特定页面(使用html5mode)
- Excel下载不适用于MEAN栈应用程序
- angularjs指令不起作用(node.js和angularjs newbee)
- 无法从request.body中提取发布的数据
- 读取其他用户时,Microsoft Graph api 403访问被拒绝
- PassportJs。 我怎样才能得到Facebook的redirecturi没有redirect用户后调用passport.authenticate('脸谱')