[英]Angular js - Append value to scope variable
我正在構建要動態創建一個數組的應用程序,該數組必須使用ng-repeat分配給動態創建的表。
在我的指令中,我添加了tr像這樣:
link: function (scope, elem, attrs) {
$(elem).click(function () {
var tmpl="<tr ng-repeat='orders in allCurrentTakeAwayOrder'>
</tr>";
});
}
這是在按鈕單擊事件上重復多次。
我想向此<tr>
附加一個動態ID
<tr ng-repeat='orders in allCurrentTakeAwayOrder"+scope.divId+"'>
並且附加成功。
但是問題是,在向該變量分配數據時,如何在該變量中附加相同的ID?
app.controller('orderController', function ($scope){
$scope.allCurrentTakeAwayOrder **<i want to append that id here>** ="data will be here to be display in table"
});
要將scope.divId
附加到范圍變量名,請使用帶有屬性訪問器的函數:
<!-- replace with function
<tr ng-repeat='orders in allCurrentTakeAwayOrder"+scope.divId+"'>
-->
<tr ng-repeat='orders in computedList()'>
JS
scope.computedList = function() {
return scope["allCurrentTakeAwayOrder"+scope.divId];
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.