我正在尝试使用按钮从名为“Students”的控制器调用“编辑”操作方法,以下是我的代码:
/*global angular*/
var app = angular.module('downtime', ['ngRoute', 'firebase']);
app.config(['$routeProvider', function ($routeProvider) {
'use strict';
$routeProvider.when('/downtime', {
templateUrl: 'downtime/downtime.html',
controller: 'downtimeCtrl'
});
}]);
app.controller('downtimeCtrl', ['$scope', '$firebaseObject', '$firebaseArray', function ($scope, $firebaseObject, $firebaseArray) {
'use strict';
$scope.allEquipments = [];
$scope.allSystems = [];
$scope.manageDowntime = function () {
var doesExist = false;
angular.forEach ($scope.data , function (d) {
angular.forEach (d.equipments, function (e) {
})
});
firebase.database().ref('downtime/' + $scope.equipment + '/downtime').push({
equipment: $scope.equipment,
type : $scope.type,
start: $scope.startDT,
end: $scope.endDT
});
};
var ref = firebase.database().ref();
var data = ref.child("data");
var list = $firebaseArray(data);
list.$loaded().then(function(data) {
$scope.data = data;
angular.forEach ($scope.data , function (d) {
$scope.allSystems.push(d.$id);
angular.forEach (d.equipments, function (e) {
$scope.allEquipments.push(e.equipment);
console.log($scope.allEquipments);
})
});
console.log($scope.data);
}).catch(function(error) {
$scope.error = error;
});
$('#datetimepicker1').datetimepicker();
$('#datetimepicker2').datetimepicker();
}]);
app.directive('customzdatetime', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
element.datetimepicker({
debug: false,
format: 'DD-MM-YYYY hh:mm'
}).on('dp.change', function (e) {
ngModelCtrl.$setViewValue(e.date);
scope.$apply();
});
}
};
});
显然它不起作用,我尝试使用Html.ActionLink方法,但它工作但我需要一个按钮而不是链接。 我还是新手使用bootstrap表,有人可以帮忙吗?
更新:忘了说Edit方法需要传递一个数字,而这个数字是来自foreach循环的item.Id。
答案 0 :(得分:0)
在onClick事件中,您可以尝试一下吗?
'<input type="button" value="Edit" onclick="window.location.href="/Students/Edit/@item.Id""/>'
它将调用Students控制器中的Edit操作。
答案 1 :(得分:0)
试试这个:
<a href='@Url.Action("Edit","Students", new {id = @item.Id})' class='btn btn-default'>Edit</a>