미니 연락처 목록에서 작업 중이며 끌어서 놓기 효과를 얻으려고합니다. 지금은 DB에서 데이터를 가져오고 이런 모습의 컨트롤러가 있습니다.지시문 내각 호출 컨트롤러 기능
Index.controller('cIndex', function($scope, $http) {
$scope.init = function() {
$http.get('php/contacts.php').success(function(data) {
$scope.jsonContactsList = data;
$scope.jsonContactsDetail = [];
});
};
$scope.init();
$scope.listdetail = function(index) {
alert(index);
};
});
이 컨트롤러는 화면에 연락처 목록을 추가합니다. 나는 목록에서 항목을 끌어서 목록 밖으로 끌어 놓으면 항목이 목록에서 사라지고 해당 특정 연락처에 대한 세부 항목으로 나타납니다.
이제 나는 드래그 효과를 만드는 1 개와 드롭 효과를 만드는 1 개의 지시문 2 개를 가지고 있습니다.
Index.directive('contactListDrag', function() {
return {
restrict: 'A',
link: function(scope, elem, attr) {
var options = scope.$eval(attr.contactListDrag);
elem.draggable(options);
}
};
});
Index.directive('contactListDrop', function() {
return {
restrict: 'A',
link: function(scope, elem, attr) {
elem.droppable({accept: '.contact-list-item'});
elem.bind('drop', function(event, ui) {
var id = parseInt($(ui.draggable).attr('id'), 10);
$scope.listdetail(id);
});
}
};
});
지금 내가이 jsonContactsDetail에 jsonContactsList 내부의 줄을 변경 만들지 만, 그렇게하기 위해 의도 listdetail라는 함수를 가지고 컨트롤러 내부에, 나는 컨트롤러에서 listdetail 함수를 호출 할 필요가 , droppable contactListDrop 지시문 내부.
미리 감사드립니다. Daniel!
무엇이 문제입니까? – Chandermani
$ scope.listdetail (id); 두 번째 지시문 내에서 $ scope.listdetail = function (index) { alert (index); }; 컨트롤러에서 –