我成功地通過Angularjs循環表來獲取名爲{{rec}}的確定作用域的值,如下所示。Angularjs循環遍歷表
HTML
<div id="AngularContainer" data-ng-app="myApp" data-ng-controller="myCtrl">
<a data-ng-click='<%# "ShowFiles("+ Eval("FilesNames") + ")" %>' style="cursor: pointer">
<table id="fils" style="display:none;">
<thead>
<tr>
<td>اسم الملف</td>
<td>مسمى الملف</td>
</tr>
</thead>
<tr data-ng-repeat="rec in records">
<td style="border: 1px solid #000000">{{rec}}</td>
// values here display successfully when I press button #Second and because there is a scope here named {{rec}}
<td style="border: 1px solid #000000">
<input data-ng-model="naming" type="text" style="width: 200px" />
// But here values not display when I press button #Second and because (data-ng-model="naming") that scope not related with {{rec}}
</td>
</tr>
<tfoot>
<tr>
<td colspan="2" style="text-align: center">
<input id="Second" data-ng-click="dothat()" class="sav" type="button" value="Save" />
</td>
</tr>
</tfoot>
</table>
<div id="fnalmsg"></div>
</div>
Angularjs
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) {
$scope.ShowFiles = function (elm) {
$scope.records = elm;
};
$scope.dothat = function() {
var msg = document.getElementById("fnalmsg");
var index = 0;
$scope.records.forEach(function (rec, naming) {
msg.innerHTML =
msg.innerHTML + 'row #' + (index++) + ': ' + JSON.stringify(rec) + ' --- ' + naming + '<br />';
});
};
});
</script>
但我專門把值通過命名(數據-NG-模型= 「命名」)未定義範圍循環問題。
而我最終的印刷視圖顯示了這樣的東西。
行#0: 「WIN_20170226_191746.JPG」 --- 0
行#1: 「WIN_20170226_191848.JPG」 --- 1
行#2: 「WIN_20170226_191908.JPG」 --- 2
應該顯示這樣的假設視圖。
行#0: 「WIN_20170226_191746.JPG」 --- 「朋友」
行#1: 「WIN_20170226_191848.JPG」 --- 「動物」
行#2: 「WIN_20170226_191908.JPG」 --- 「汽車」
換句話說:我如何讓(data-ng-model =「naming」)顯示名稱,如「朋友」,「動物」,「汽車」 「輸入,而不是顯示不需要的值,如0,1,2?
命名不屬於REC。所以簡單的json只包含一個沒有名字的列。所以我不能這樣做「rec.naming」,同時我知道重複範圍命名返回數組值,所以如果有任何方法可以通過索引來返回這些值,這將解決我的問題。我在dothat函數(命名[index ++]而不是命名)中考慮了一些這樣的事情,但我無法修復該解決方案。 –
我想我不明白爲什麼第二種方法不適合你。 – anveshtummala
其實data-ng-model =「命名[$ index]」給了我這樣的結果(第0行:「〜\\ 191746.JPG」--- undefined),所以它返回「undefined」。 –