Javascript ng重复不填充表
我已经用JSON文件中的数据填充了一个表,然后当用户单击表中的一个项目时,下面会显示一个容器及其字段,应该用特定的数据填充它,尽管它不是 通过Javascript ng重复不填充表,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,我已经用JSON文件中的数据填充了一个表,然后当用户单击表中的一个项目时,下面会显示一个容器及其字段,应该用特定的数据填充它,尽管它不是 通过list patents.htm调用函数select,该函数包含专利列表表。我使用了$rootScope对象,因此可以从多个控制器(即patentDetailsCtrl 为什么patent item.htm中的我的表中没有填充ng repeat指令 var app = angular.module('myApp', ['ngRoute', 'angular
list patents.htm
调用函数select
,该函数包含专利列表表。我使用了$rootScope
对象,因此可以从多个控制器(即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);
}]);
列出专利.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>
<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>
{{x.applicationNumber}
$
去除
专利项目.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>
<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>
应用程序编号
clientRef
科斯特雷恩
更新日期
篮球运动员地位
costBandEnd
下一阶段
{{x.applicationNumber}
{{x.clientRef}}
{{x.costToRenew}
{x.renewalDueDate}
{{x.basketStatus}
{x.costBandEnd}
{x.nextStage}
在我看来,您似乎正在尝试访问在选择功能中选择的专利。如果以这种方式将其传递给$rootScope,则还需要以这种方式访问它 因此,将行更改如下
$scope.selectedPatent = $rootScope.patentItem
您需要纠正以下几点:
$rootScope.select()
方法不接受从list patents.htm
传递的数据(select(x)
),因此将项作为参数。,
类似:$rootScope.select=函数(项){\\code
$rootScope.patentItem
上执行ng repeat
,那么我想您需要将其设置为数组
,并将传递的数据推送到它
(也不需要返回语句)app.run(function($rootScope) {
rootScope.patentItem = [];
$rootScope.select = function(item) {
$rootScope.patentItem.push(item);
}
});
查看此代码中的键入错误。在
$rootScope处缺少paradensis。选择。首先确保没有语法错误,正在删除控制台。在返回$rootScope.patentItem=item;
行中,记录什么是项de>$rootScope
,据我所知,我可以从我的任何控制器中使用$scope
访问它。不行,根范围中的函数必须由$rootScope从任何控制器访问,而不仅仅是$scope,但当您说$rootScope时,您仍然可以从任何视图(html)正常访问它。选择()方法不接受数据,这怎么可能?所选对象显示在我的控制台中。我只需要解决如何仅用该信息填充后续表当您执行ng click=“select(x)”
时,x
将去哪里?我希望它将由rotscope方法执行,如$rootScope.select=函数(项){
,您进一步将其分配给$rootScope.patentItem
,相反,您应该推送它。。希望它澄清…:)它是由$rootScope.select函数获取的。我想我误解了您的意思。我想您是说它不接受来自视图的参数,但它确实显示了我想要在conso中显示的所有细节现在我要做的就是用ng repeat
填充第二个表,但它不显示datasee更新的答案。请确保在控制台中的console.log($scope.selectedPatent);
在控制器中之后获得数据?