如果满足特定条件,我需要用户确认离开页面。问题是位置更改不等待对话框让用户回答。
这是我的代码:
角度模块1:
...
function confirmLeavePage(e, newUrl) {
if(form.cod.value) {
customDialog.confirmDialog('Title','Leave?').then(
function(){
console.log('go to selected page');
},function(){
e.preventDefault();
});
}
}
$scope.$on("$locationChangeStart", confirmLeavePage);
...
角度模块2:
angular.module('dialog').service('customDialog', function($mdDialog, $q, $location) {
this.confirmDialog = function(title, content){
var deferred = $q.defer();
$mdDialog.show($mdDialog.confirm({
templateUrl:'confirmDialog.html',
title : title,
textContent : content,
ok : 'Confirm',
cancel: 'Cancel'
})).then(function() {
console.log('confirmed');
deferred.resolve();
}, function() {
console.log('abort');
deferred.reject();
});
return deferred.promise;
}
});
有什么想法吗?
答案 0 :(得分:0)
试试这个
#reshape datetime columns to one, create datetimeindex
df1 = pd.melt(df.reset_index(), id_vars=['EMI', 'index'], value_name='date')
.set_index('date')
#convert index to periodindex by month
df1.index = pd.to_datetime(df1.index, format='%d/%m/%y', errors='coerce')
.to_period('M')
#groupby by column index nad resample by month
df1 = df1.groupby('index')
.resample('M')
.ffill()
.drop(['variable', 'index'], axis=1)
.reset_index()
#pivoting, fill NaN with 0, cast floats to int
df1 = df1.pivot(index='index', columns='date', values='EMI')
.fillna(0)
.astype(int)
#change format of columns
df1.columns = df1.columns.strftime('%m/%y')
#concat original dataframe
df = pd.concat([df,df1], axis=1)
print (df)
Start Date End Date EMI 07/15 08/15 09/15 10/15 11/15 12/15 01/16 \
0 01/12/16 01/12/17 4800 0 0 0 0 0 0 0
1 09/01/16 09/01/17 3000 0 0 0 0 0 0 3000
2 01/07/15 01/05/16 2300 2300 2300 2300 2300 2300 2300 2300
03/17 04/17 05/17 06/17 07/17 08/17 09/17 10/17 11/17 12/17
0 ... 4800 4800 4800 4800 4800 4800 4800 4800 4800 4800
1 ... 0 0 0 0 0 0 0 0 0 0
2 ... 0 0 0 0 0 0 0 0 0 0
[3 rows x 33 columns]