gpt4 book ai didi

ruby-on-rails - AngularJS 和 Rails View 需要页面刷新

转载 作者:行者123 更新时间:2023-12-01 02:19:58 25 4
gpt4 key购买 nike

在某些 View 中,我有一个带有 AngularJS 的 Rails 应用程序。每当我单击将我带到页面的链接时,请说 /certifications我看到这个

bad reload

然后,当我重新加载页面或通过在 url 栏中按 enter 来请求它时,它会工作并显示这个

good reload

这两个页面的重新加载方式是否存在差异,这会搞砸 AngularJS。我需要用户和 Angular 路由器吗?我已将 View 和 Controller 的代码放在下面。谢谢您的帮助!

Controller :

@aquaticsApp = angular.module 'aquaticsApp',
['ngResource', 'aquaticsAppFilters']


@aquaticsApp.controller 'CertsCtrl', ['$scope', 'Certs',
@CertsCtrl = ($scope, Certs) ->
$scope.formatDate = (dateString) ->
d = new Date(dateString)

curr_month = d.getMonth() + 1
curr_date = d.getDate()
curr_year = d.getFullYear()

"#{curr_month}/#{curr_date}/#{curr_year}"

$scope.sorter =
value: 'firstName'

Certs.get (data) ->
$scope.certNames = data.certification_names
$scope.users = data.users
]

看法:
<div ng-app='aquaticsApp' class='table-responsive'>
<table ng-controller='CertsCtrl' class='table table-hover table-condensed'>
<thead>
<tr>
<th ng-click='sorter.value="lastName"'>Last Name</th>
<th ng-click='sorter.value="firstName"'>First Name</th>
<th ng-click='sorter.value="location"'>Location</th>
<th ng-repeat='certName in certNames' ng-click='sorter.value=certName.name'>
{{certName.name}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='userData in users | orderBy:sorter.value'>
<td>{{userData.lastName}}</td>
<td>{{userData.firstName}}</td>
<td>{{userData.location}}</td>
<td ng-repeat='certName in certNames' class='{{userData[certName.name + "class"]}}'>
{{formatDate(userData[certName.name])}}
</td>
</td>
</tr>
</tbody>
</table>
</div>

最佳答案

在这里找到答案 JQuery gets loaded only on page refresh in Rails 4 application .

Turbolinks 会阻止绑定(bind)到准备好的文档的插件工作。由于我认为我会继续使用 turbolinks,因此我使用了上述 SO 答案中规定的解决方案并且它有效。

关于ruby-on-rails - AngularJS 和 Rails View 需要页面刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21261348/

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