加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – AngularJS和Rails视图需要页面刷新

发布时间:2020-12-17 02:22:00 所属栏目:百科 来源:网络整理
导读:我在一些视图中有一个带有AngularJS的Rails应用程序.每当我点击链接将我带到一个页面时,说/证明我就会看到这个 然后当我重新加载页面或通过在URL栏中输入来请求它时,它可以工作并显示这一点 重新加载这两个页面是否会导致AngularJS混乱.我需要用户和角度路由
我在一些视图中有一个带有AngularJS的Rails应用程序.每当我点击链接将我带到一个页面时,说/证明我就会看到这个

然后当我重新加载页面或通过在URL栏中输入来请求它时,它可以工作并显示这一点

重新加载这两个页面是否会导致AngularJS混乱.我需要用户和角度路由器或什么?我已将视图和控制器的代码放在下面.谢谢您的帮助!

控制器:

@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会停止绑定到文档准备工作的插件.因为我认为我会继续使用turbolinks,所以我使用了上述SO答案中规定的解决方案,并且它有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读