【发布时间】:2017-05-27 20:25:55
【问题描述】:
我成功地通过 Angularjs 遍历表,以获取名为 {{rec}} 的确定范围的值,如下所示。
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>
但我在循环未定义的名为 (data-ng-model="naming") 的作用域时遇到了问题,该作用域专门用于放置值。
我的最终打印视图显示了类似这样的内容。
第 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") 以 ng-model="naming" 输入而不是显示不需要的值,例如 0,1,2?
【问题讨论】:
标签: javascript angularjs