我有搜索页面,因此用户可以使用名字,姓氏和电子邮件地址进行搜索。无论用户传递给工厂的变量是什么,我想获得匹配结果,所以在下面的代码中,如果我传递一个变量,其他的都是未定义的,如何避免这个问题并使用get请求?
到目前为止尝试过代码......
main.html中
<div class="row">
<div class="col-md-12">
<div class="col-md-3"> First / Last
Name :
</div>
<div class="col-md-3">
<input type="text" class="form-control" id="attestorFirstName" ng-model="attestorDTO.firstName" />
</div>
<div class="col-md-3">
<input type="text" class="form-control" id="attestorLastName" ng-model="attestorDTO.lastName" />
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-12">
<div class="col-md-3"> Email Address :
</div>
<div class="col-md-6">
<input type="text" class="form-control" id="attestorMail" ng-model="attestorDTO.emailId" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-default pull-right" type="button" ng-click="searchAttestor()">
Search</button>
</div>
</div>
<div kendo-grid="attestorSearch" options="attestorSearchOptions" k-rebind="getAttestorSearchResultGrid"></div>
main.Ctrl
$scope.searchAttestor = function() {
$scope.searchresult = '';
$scope.attestorSearchOptions.dataSource = rcsaAssessmentService
.getOwnerSearchGridDataSource(
$scope.attestorDTO.firstName,
$scope.attestorDTO.lastName,
$scope.attestorDTO.emailId,
$scope.attestorDTO.nbkId);
$scope.getAttestorSearchResultGrid = new Date().getTime();
console.log("getting the response");
console.log($scope.attestorDTO.lastName);
};
mainFactory.js
getOwnerSearchGridDataSource : function(fName, lName,
mailId, nbkId) {
return new kendo.data.DataSource({
type : 'json',
transport : {
read : function(options) {
return $http.get(
'app/assessment/rest/ownerList?firstName=' +
fName + '&lastName=' +
lName + '&emailId=' +
mailId + '&nbkId=' +
nbkId).success(
function(data) {
options.success(data);
});
}
},
pageSize : 5,
schema : {
model : {
fields : {
fullName : {
editable : false
},
workEmailAddressText : {
editable : false
},
stdId : {
editable : false
}
}
},
}
});
},
答案 0 :(得分:1)
只需使用$http.post
代替$http.get
-
但是使用get参数将其提供给url,如下所示:
return $http.post('app/assessment/rest/ownerList?firstName=' +
fName + '&lastName=' +
lName + '&emailId=' +
mailId + '&nbkId=' +
nbkId,
{ postDataKey1 : "Post Data Value1",
postDataKey2 : "Post Data Value2"
}).success(function(data) {
options.success(data);
});