easyui实现日期下拉框简单好使,angular做前后端交互高效强大,那么如何让两者优点结合?
请看代码!
HTML:
<span style="font-size: 20px">起始时间 </span>
<input id="txtBeginTime" name="beginTime" style="height: 25px;width: 120px" class="easyui-datebox"
data-options="formatter:myformatter,parser:myparser"><b>--</b>
<span style="font-size: 20px">结束时间 </span>
<input id="txtEndTime" name="endTime" style="height: 25px;width: 120px" class="easyui-datebox"
data-options="formatter:myformatter,parser:myparser">
<input type="button" style="margin-left:10px;width:50px;height:30px" value="查询"
ng-click="setTime()"/>
jquery:
//easyui日期格式
function myformatter(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
if (!s) return new Date();
var ss = (s.split('-'));
var y = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var d = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
angular-controller:
//控制层
app.controller('baseController' ,function($scope,baseService){
$scope.searchEntity.beginTime = $("#txtBeginTime").val();
$scope.searchEntity.endTime = $("#txtEndTime").val();
$scope.setTime = function() {
$scope.searchEntity.beginTime = $("#txtBeginTime").val();
$scope.searchEntity.endTime = $("#txtEndTime").val();
}
//搜索
$scope.search=function(page,rows){
//console.debug($scope.depotId);
$scope.depotId = ($scope.depotArr)[0].deportId;
baseService.search(page,rows,$scope.searchEntity).success(
function(response){
$scope.list=response.body.rows;
$scope.paginationConf.totalItems=response.body.total;//更新总记录数
}
).error(
function (response) {
alert(response.message)
}
);
}
});
angular-service:
//服务层
app.service('profitService', function ($http) {
//搜索
this.search = function (page, rows,depotId,searchEntity) {
return $http.get('/info/base?page=' + page + "&rows=" + rows + "&depotId="+depotId + "&beginTime=" + searchEntity.beginTime+ "&endTime=" + searchEntity.endTime);
}
});
效果如下:
部分代码已省略,实现基本原理是已jquery或者js作为中间变量传递数据