javascript - Given the array used with ng-repeat, can I select an individual item created with each item? -
i have angular app builds list of zones map data. zones displayed both in sidebar in divs using ng-repeat, , on map vector features. when user selects zone on map, need scroll zone's div in sidebar. jquery can perform scrollto action given element, , know zone selected; can reference div matches item?
i cannot use index because there may sorting or filtering on ng-repeat array. other options?
edit:
here's relevant code:
<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>
openlayers call function when 1 of zones on map clicked:
zonelayer.events.register("featureselected", null, function(e){ var zone=e.feature; var element = null; // how element? $(element).scrollto(); // or similar });
if zone objects have id or other identifier add 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>
then find zone id
zonelayer.events.register("featureselected", null, function(e){ var zone=e.feature; var element = $("#" + zone.id); // how element? $(element).scrollto(); // or similar });
if can't afford add ids divs add data-zoneid
attribute , find element attribute var element = $("div[data-zoneid=" + zone.id + "]");
Comments
Post a Comment