gpt4 book ai didi

javascript - ng-repeat 不填充表

转载 作者:行者123 更新时间:2023-12-03 04:09:06 25 4
gpt4 key购买 nike

我已经用 JSON 文件中的数据填充了一个表,然后当用户单击表中的某个项目时,下面会显示一个容器及其字段,并且应该使用该特定数据来填充它,尽管它不是“t。

函数select通过list-patents.htm调用,其中包含带有专利列表的表格。我使用了 $rootScope 对象,因此可以从多个 Controller 访问该函数,即 patentDetailsCtrl

为什么 patent-item.htm 中的表格没有使用 ng-repeat 指令填充?

var app = angular.module('myApp', ['ngRoute', 'angularMoment', 'ui.router', "chart.js"]);

$stateProvider
.state("patents.list.item", {
url: "/patent-item",
templateUrl: "templates/patents/list/patent-item.htm",
params: {
id: null,
appNo: null,
clientRef: null,
costToRenew: null,
renewalDueDate: null,
basketStatus: null,
costBandEnd: null,
nextStage: null
},
controller: "patentDetailsCtrl"
})

app.run(function($rootScope) {
$rootScope.select = function() {
return $rootScope.patentItem = item;
}
});

app.controller('patentDetailsCtrl', ['$scope', '$http', function($scope, $http) {

$scope.selectedPatent = $scope.patentItem;

console.log($scope.selectedPatent);


}]);
<小时/>

list-patents.htm

<tbody>
<tr ng-repeat="x in patents">
<td ng-click="select(x)"><a ui-sref="patents.list.item({id: x.id, appNo: x.applicationNumber, clientRef: x.clientRef, costToRenew: x.costToRenew, renewalDueDate: x.renewalDueDate, basketStatus: x.basketStatus, costBandEnd: x.costBandEnd, nextStage: x.nextStage})">{{x.applicationNumber}}</a></td>
<td ng-bind="x.clientRef"></td>
<td ng-bind="x.costToRenew">$</td>
<td ng-bind="x.renewalDueDate"></td>
<td><button type="button" class="btn btn-danger" ng-click="remove(x.id)">Remove</button></td>
</tr>
</tbody>

专利项.htm

<table>
<tbody>
<thead>
<tr>
<td>applicationNumber</td>
<td>clientRef</td>
<td>costToRenew</td>
<td>renewalDueDate</td>
<td>basketStatus</td>
<td>costBandEnd</td>
<td>nextStage</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in selectedPatent">
<td>{{x.applicationNumber}}</td>
<td>{{x.clientRef}}</td>
<td>{{x.costToRenew}}</td>
<td>{{x.renewalDueDate}}</td>
<td>{{x.basketStatus}}</td>
<td>{{x.costBandEnd}}</td>
<td>{{x.nextStage}}</td>
</tr>
</tbody>
</table>
</tbody>

最佳答案

您需要更正以下几点:

  1. 您的 $rootScope.select() 方法不接受从 list-patents.htm 传递的数据 (select(x)) ,所以将item作为参数,例如: $rootScope.select = function(item) {\\code

  2. 正弦你在$rootScope.patentItem上执行ng-repeat,那么我想你需要将其设为array,并且将传递的数据推送给它。 (也不需要 return 语句。)

所以运行 block 应该是这样的:

app.run(function($rootScope) {
rootScope.patentItem = [];
$rootScope.select = function(item) {
$rootScope.patentItem.push(item);
}
});

查看此Example Fiddle

关于javascript - ng-repeat 不填充表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44408664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com