3
我有兩個型號命名爲「牛仔」和「襯衫」 其中有兩個變量「名」與「色」搜索
我想有一個搜索頁面,用戶可以通過數據庫搜索特定顏色或名稱的襯衫和牛仔褲。
此鏈接可能是一個暗示,但我無法弄清楚 Similar Problem
我已經得到的東西在這裏,但它不工作。 我很感激你告訴我如何解決它。謝謝!
查看
<section data-ng-controller="AllsController" data-ng-init="find()">
<div class="page-header">
<h1>Alls</h1>
</div>
<div class="Search">
<h2>Search Section</h2>
<select data-ng-model="search1" id="search">
<option value="Model1">Jeans</option>
<option value="Model2">Shirts</option>
</select>
<select data-ng-model="search2" id="search">
<option value="Model1">Jeans</option>
<option value="Model2">Shirts</option>
</select>
<select data-ng-model="variable1" id="variable1">
<option selected="selected">AnyThing</option>
<option value="color1">Blue</option>
<option value="color2">Red</option>
</select>
<select data-ng-model="variable2" id="variable2">
<option selected="selected">AnyThing</option>
<option value="name1">John</option>
<option value="name2">Bob</option>
</select>
</div>
<br></br><br></br>
<h2>Result Section</h2>
<div class="list-group">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Color</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="all in alls">
<td data-ng-bind="all.name"></td>
<td data-ng-bind="all.color"></td>
</tr>
</tbody>
</table>
</div>
在控制器;第一個我看到的性能用戶選擇並指定爲FindArray 後來我在其中看到模型的用戶要搜索。(什麼意味着用戶沒有選擇任何東西)
服務器端控制器
exports.list = function(req, res) {
if (variable1 === "AnyThing")
{
if (variable2 === "AnyThing")
{
FindArray = {};
}else
{
FindArray = { name = variable2 };
}
}else
{
FindArray = { color = variable1 , name = variable2 };
}
if (req.body.search1 === 'Jeans')
{
if (req.body.search2 === 'Shirts')
{
Jeans.find(FindArray).sort('-created').populate('user', 'displayName').exec(function(err, jeans) {
Shirt.find(FindArray).sort('-created').populate('user', 'displayName').exec(function(err, shirts) {
var all = shirts.concat(jeans);
res.jsonp(all);
});
});
}else{
Jeans.find(FindArray).sort('-created').populate('user', 'displayName').exec(function(err, jeans) {
res.jsonp(jeans);
});
}
}else{
Shirt.find(FindArray).sort('-created').populate('user', 'displayName').exec(function(err, shirts) {
res.jsonp(shirts);
});
}
};
$資源服務:
angular.module('alls').factory('Alls', ['$resource',
function($resource) {
return $resource('alls/:allId', { allId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}]);
客戶端控制器
angular.module('alls').controller('AllsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Alls', 'Jeans', function($scope, $stateParams, $location, Authentication, Alls, Jeans) {
$scope.find = function() {
$scope.search1 = search1;
$scope.search2 = search2;
$scope.variable1 = variable1;
$scope.variable2 = variable2;
$scope.alls = Alls.query();
};
}]);
服務器端路線
module.exports = function(app) {
var alls = require('../../app/controllers/alls.server.controller');
app.route('/alls').get(alls.list);
};
它是如何不準確地工作?你期望發生哪些事情沒有發生?你是否從客戶端獲取服務器上的表單數據?數據庫查找不起作用或者是什麼? – laggingreflex
它是關於控制器 我想我的控制器不能識別search1和search2和變量1和變量2 當我添加這些行我的應用程序dos沒有顯示任何東西! 我是否需要將視圖中的數據發送給控制器? 原因我只有GET的路線,我想我需要發送這些變量到我的控制器。 當我註釋掉這些變量時,我的視圖顯示整個數據庫意味着我可以從數據庫讀取到我的視圖因此,我認爲我需要將數據從我的視圖發送到控制器 –
如果您有任何簡單的搜索頁面,將是一個很大的幫助 –