我有一個指令稱爲「向下鑽取」我想要的功能,如下一個內部電話,但我不知道如何做到這一點在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>
一些幫助將是巨大的!
指示的代碼
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