如何获取每个data-id值

时间:2016-12-27 13:05:58

标签: javascript jquery

我正在尝试找到每个 func scrollViewDidScroll(_ scrollView: UIScrollView) { if(scrollView.contentOffset.y <= 0) { if(scrollView.frame.size.height == view.frame.size.height - navigationController!.navigationBar.frame.size.height - tabBarController!.tabBar.frame.size.height) { UIView.animate(withDuration: 0.5, animations: { self.coverImage.center = CGPoint(x: self.view.frame.size.width / 2, y: self.navigationController!.navigationBar.frame.size.height + (self.coverImage.frame.size.height / 2)) self.profileImage.center = CGPoint(x: self.coverImage.center.x, y: self.coverImage.center.y + (self.coverImage.frame.size.height / 2)) self.verifiedLogo.center = CGPoint(x: self.profileImage.center.x + (self.profileImage.frame.size.width / 3), y: self.profileImage.center.y - (self.profileImage.frame.size.height / 3)) self.usernameLabel.center = CGPoint(x: self.view.frame.size.width / 2, y: self.profileImage.center.y + (self.profileImage.frame.size.height / 2) + (self.usernameLabel.frame.size.height / 2)) self.biographyLabel.center = CGPoint(x: self.view.frame.size.width / 2, y: self.usernameLabel.center.y + (self.usernameLabel.frame.size.height / 2) + (self.biographyLabel.frame.size.height / 2)) self.biographyTextfield.center = self.biographyLabel.center self.biographyCharactersLabel.center = CGPoint(x: self.view.frame.size.width / 2, y: self.biographyTextfield.center.y + self.biographyCharactersLabel.frame.size.height) self.editImagesLogo.center = CGPoint(x: self.view.frame.size.width - self.editImagesLogo.frame.size.width, y: self.navigationController!.navigationBar.frame.size.height + (self.editImagesLogo.frame.size.height * 2)) self.editBiographyImage.center = CGPoint(x: self.view.frame.size.width - (self.editBiographyImage.frame.size.width * 1.5), y: self.biographyLabel.center.y) self.editImagesView.center = CGPoint(x: self.editImagesLogo.center.x + (self.editImagesLogo.frame.size.width / 2) - (self.editImagesView.frame.size.width / 2), y: self.editImagesLogo.center.y + (self.editImagesLogo.frame.size.height / 2) + (self.editImagesView.frame.size.height / 2)) self.doneImage.center = self.editBiographyImage.center self.nextImage.center = CGPoint(x: self.view.frame.size.width - (self.nextImage.frame.size.width / 1.5), y: self.view.frame.size.height - (self.nextImage.frame.size.height / 1.25) - self.navigationController!.navigationBar.frame.size.height) self.photoCollectionView.frame.size.height = self.view.frame.size.height - self.biographyLabel.center.y - 75 - self.navigationController!.navigationBar.frame.size.height self.photoCollectionView.center = CGPoint(x: self.view.frame.size.width / 2, y: self.view.frame.size.height - (self.photoCollectionView.frame.size.height / 2) - self.navigationController!.navigationBar.frame.size.height) }, completion: { (true) in self.navigationItem.setHidesBackButton(false, animated: false) for barButtons in self.tabBarController!.tabBar.items! { barButtons.isEnabled = true } }) } }else{ if(scrollView.frame.size.height == self.view.frame.size.height - self.biographyLabel.center.y - 75 - self.navigationController!.navigationBar.frame.size.height) { navigationItem.setHidesBackButton(true, animated: false) for barButtons in tabBarController!.tabBar.items! { barButtons.isEnabled = false } UIView.animate(withDuration: 0.5, animations: { self.coverImage.center.y = -(self.coverImage.frame.size.height / 2) self.profileImage.center.y = -(self.profileImage.frame.size.height / 2) self.verifiedLogo.center.y = -(self.verifiedLogo.frame.size.height / 2) self.usernameLabel.center.y = -(self.usernameLabel.frame.size.height / 2) self.biographyLabel.center.y = -(self.biographyLabel.frame.size.height / 2) self.biographyTextfield.center.y = -(self.biographyTextfield.frame.size.height / 2) self.doneImage.center.y = -(self.doneImage.frame.size.height / 2) self.biographyCharactersLabel.center.y = -(self.biographyCharactersLabel.frame.size.height / 2) self.editImagesLogo.center.y = -(self.editImagesLogo.frame.size.height / 2) self.editBiographyImage.center.y = -(self.editBiographyImage.frame.size.height / 2) self.editImagesView.center.y = -(self.editImagesView.frame.size.height / 2) self.nextImage.center.y = -(self.nextImage.frame.size.height / 2) self.photoCollectionView.frame.size.height = self.view.frame.size.height - self.navigationController!.navigationBar.frame.size.height - self.tabBarController!.tabBar.frame.size.height self.photoCollectionView.center = self.view.center }) } } } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if(photoLinks.isEmpty) { photoCollectionView.isHidden = true return 0 }else{ photoCollectionView.isHidden = false return photoLinks.count } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = photoCollectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as! PhotosCollectionViewCell cell.awakeFromNib() cell.photoImage.image = nil if(loadedPhotos.count == photoLinks.count) { cell.photoImage.image = loadedPhotos[indexPath.row] }else{ let photoLink = photoLinks[indexPath.row] let url = URL(string: photoLink) URLSession.shared.dataTask(with: url!) { (data, response, error) in if(error != nil){ print(error as Any) return } DispatchQueue.main.async { if let downloadedImage = UIImage(data: data!) { let image = downloadedImage cell.photoImage.image = image self.loadedPhotos.append(image) } } }.resume() } return cell } ,然后将它们打印到控制台。

我尝试了以下内容:

&#13;
&#13;
data-id
&#13;
$('.raffle-user-entries .raffle-user-entry').each(function() {
  console.log($(this).find('raffle-user-entry-item').data('id'))
})
&#13;
&#13;
&#13;

Extended example

1 个答案:

答案 0 :(得分:0)

更新了小提琴:https://jsfiddle.net/f5w56wp3/1/

  • Jquery不包括在小提琴中
  • $(this).find('raffle-user-entry-item').data('id')在find中的选择器上错过了一个点,而且其中的锚点上也存在data-id

修正:

$('.raffle-user-entries .raffle-user-entry').each(function(){
    console.log($(this).find('.raffle-user-entry-item a').data('id'))
})