Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 给定与ng repeat一起使用的数组,我可以选择使用每个项创建的单个项吗?_Javascript_Jquery_Angularjs_Openlayers - Fatal编程技术网

Javascript 给定与ng repeat一起使用的数组,我可以选择使用每个项创建的单个项吗?

Javascript 给定与ng repeat一起使用的数组,我可以选择使用每个项创建的单个项吗?,javascript,jquery,angularjs,openlayers,Javascript,Jquery,Angularjs,Openlayers,我有一个angular应用程序,它可以根据地图数据构建区域列表。分区使用ng repeat显示在divs的侧栏中,并在地图上显示为矢量要素。当用户在地图上选择一个区域时,我需要在侧边栏中滚动到该区域的DIV。jQuery可以在给定元素的情况下执行scrollTo操作,我知道选择了哪个区域;我可以获得与该项匹配的DIV的引用吗 我无法使用索引,因为ng repeat数组上可能存在排序或筛选。还有其他选择吗 编辑: 以下是一些相关代码: <div class="turf" ng-rep

我有一个angular应用程序,它可以根据地图数据构建区域列表。分区使用ng repeat显示在divs的侧栏中,并在地图上显示为矢量要素。当用户在地图上选择一个区域时,我需要在侧边栏中滚动到该区域的DIV。jQuery可以在给定元素的情况下执行scrollTo操作,我知道选择了哪个区域;我可以获得与该项匹配的DIV的引用吗

我无法使用索引,因为ng repeat数组上可能存在排序或筛选。还有其他选择吗

编辑:

以下是一些相关代码:

<div class="turf"
    ng-repeat="zone in layers.zones.features"
    ng-class="{
        selected: zone === selectedZone && zone !== highlightedZone,
        hover: zone === highlightedZone
    }"
    ng-click="selectZone(zone); $event.stopPropagation()">

    <h2>{{zone.name}}</h2>
    <input type="text" class="form-control" ng-model="zone.name" />
    {{zone.users}} users present
</div>

如果区域对象具有ID或其他标识符,则将ID添加到div中

<div class="turf"
    id="{{zone.ID}}"
    ng-repeat="zone in layers.zones.features"
    ng-class="{
        selected: zone === selectedZone && zone !== highlightedZone,
        hover: zone === highlightedZone
    }"
    ng-click="selectZone(zone); $event.stopPropagation()">

    <h2>{{zone.name}}</h2>
    <input type="text" class="form-control" ng-model="zone.name" />
    {{zone.users}} users present
</div>

如果您负担不起向div添加ID,那么添加data zoneID属性并通过该属性var element=$div[data zoneID=+zone.ID+]查找元素

请发布一些代码。您需要做的是为每个边栏div附加一个唯一的id,并将该id存储在相应的映射区域中的某个位置-但是您如何做到这一点完全取决于您如何生成映射。这可能有助于实际的滚动:我将发布一些代码,但这是非常通用的ng重复内容,并且处理程序都是OpenLayers。
<div class="turf"
    id="{{zone.ID}}"
    ng-repeat="zone in layers.zones.features"
    ng-class="{
        selected: zone === selectedZone && zone !== highlightedZone,
        hover: zone === highlightedZone
    }"
    ng-click="selectZone(zone); $event.stopPropagation()">

    <h2>{{zone.name}}</h2>
    <input type="text" class="form-control" ng-model="zone.name" />
    {{zone.users}} users present
</div>
zoneLayer.events.register("featureselected", null, function(e){
    var zone=e.feature;
    var element = $("#" + zone.ID); // how do I get the element?

    $(element).scrollTo(); // or similar
});