で関数内の呼び出し指示、私は以下の一つとして、関数内で呼び出したいが、私は、私が使用して今、このAngularJS
$scope.drillDown = function() {
some code...
if(success == 200) {
call the directive here
}
}
を行う方法を知らない「ドリルダウン」と呼ばれるディレクティブを持っていますそのような私の見解でその指示:
<tr ng-repeat="d in data" class="child">
<td ng-click="drillDown()" drill-down></td>
<td>d.name</td>
<td>d.lastname</td>
</tr>
いくつかの助けになるでしょう!
ディレクティブCODE
angular.module('headline.Drilldown',[])
.directive('drillDown',drillDown);
function drillDown() {
var directive = {
restrict: 'A',
link: link
};
return directive;
function link(scope,element) {
var table = $('.categories-table');
table.each(function() {
var $table = $(this);
$table.find('.parent').each(function(){
if($(this).nextUntil('.parent', ".child").length >= 0){
$(this).children('td:first').html('+');
}
});
$table.find('.child').each(function(){
if($(this).nextUntil('.child', ".grandson").length >= 0){
// $(this).children('td:first').html('+');
}
});
var $childRows = $table.find('tbody tr').not('.parent').hide();
$table.find('button.hide').click(function() {
$childRows.hide();
});
});
element.on('click',function(){
if($(this).parent().hasClass('parent') === true)
{
console.log("----Parent");
if ($(this).text() === "+")
$(this).text("-")
else
$(this).text("+");
$(this).parent().nextUntil('.parent', ".child").fadeToggle("fast", "linear");
$(this).parent().nextUntil('.parent', ".grandson").hide("fast");
$(this).parent().nextUntil('.parent', ".child").each(function(){
if($(this).children('td:first').text() === '-')
$(this).children('td:first').text('+');
});
}
else if($(this).parent().hasClass('child') === true)
{
console.log("----Child");
if ($(this).text() === "+")
$(this).text("-")
else
$(this).text("+");
$(this).parent().nextUntil('.child', ".grandson").fadeToggle("fast", "linear");
}
});
}
}
あなたのディレクティブのコードがありますか? – tanenbring
こんにちは、ありがとうございます。 私は疑問符を指示コードで更新します。 – kennechu
指令の目的が何であるか明確ではありません。このディレクティブが何をしているのか、そしてあなたが望むものを達成するために既存のディレクティブを使用するだけではない理由を説明できますか?また、これが最初に投稿されたときに言及された人のように、あなたが監視または観察するディレクティブに変数を渡し、そのプロパティの値が変更されたときにディレクティブ内の作業を行います。 – shaunhusain