[英]Angularjs ng-repeat: how to target an element
我有一個div元素列表,當客戶選擇一個元素時,將顯示詳細信息視圖。 在后面之后,我想將列表指向選定的元素。
<div id="patient{{patient.PId}}" class="div-patient" ng-repeat="patient in patients">
<p>{{patient.name}}</p>
</div>
我已經測試了許多代碼以在選定的患者上滾動:
$(window).scrollTop($("#patient"+$rootScope.selectedPatient).offset().top);
// or
$("html, body").animate({ scrollTop:angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ) });
//or
$(window).scrollTop(angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ));
CSS div患者:
position: absolute;
height: 330px;
margin-bottom: 30px;
top: {{360*fixTopCell($index)}}px;
但
$("#patient"+$rootScope.selectedPatient).offset().top
和
angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' )
一直返回0。
tag instead of a . 當我使用標簽而不是時,它可以工作。
我看到功能scrollTop在Android 4.X中不可用。 是否有其他解決方案可以將列表中的選定元素作為目標?
當我使用div的表標記INSTEAD時,它起作用。
確保您的ID尚未使用#patient
。 也許您嘗試調用已使用的ID!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.