我知道标题很糟糕,但我不知道会有什么更好。
根据$(window).width()
,根据$(window).resize()
,我在绝对坐标内创建了几个带有div的跨距。当我调整它的大小时,我想重新排列它们,所以在$("span").empty();
上我调用函数来删除跨度,#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "Price.h"
@interface DataPrice : NSManagedObject
@property (nonatomic) NSInteger id;
@property (nonatomic, retain) NSNumber *ron95;
@property (nonatomic, retain) NSNumber *ron92;
@property (nonatomic, retain) NSNumber *dieselNormal;
@property (nonatomic, retain) NSNumber *dieselSpecial;
@property (nonatomic, retain) NSDate *postDate;
+ (instancetype)insertDataPriceWithPrice:(Price*)price
inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext;
+ (instancetype)fetchDataPriceInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext;
+ (Price*)fetchPriceInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext;
@end
#import "DataPrice.h"
@implementation DataPrice
@dynamic id;
@dynamic ron95;
@dynamic ron92;
@dynamic dieselNormal;
@dynamic dieselSpecial;
@dynamic postDate;
+ (instancetype)insertDataPriceWithPrice:(Price*)price
inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
{
DataPrice* dataPrice = [NSEntityDescription insertNewObjectForEntityForName:self.entityName
inManagedObjectContext:managedObjectContext];
dataPrice.id = price.id;
dataPrice.ron95 = price.ron95;
dataPrice.ron92 = price.ron92;
dataPrice.dieselNormal = price.dieselNormal;
dataPrice.dieselSpecial = price.dieselSpecial;
dataPrice.postDate = price.postDate;
return dataPrice;
}
+ (NSString*)entityName
{
return @"Price";
}
+ (instancetype)fetchDataPriceInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext {
NSEntityDescription *entity = [NSEntityDescription entityForName:self.entityName inManagedObjectContext:managedObjectContext];
if (!entity) {
return NULL;
}
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"postDate" ascending:NO];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = entity;
request.sortDescriptors = @[ sortDescriptor ];
request.fetchLimit = 1;
NSError *error;
NSArray *fetchResults = [managedObjectContext executeFetchRequest:request error:&error];
DataPrice *result = fetchResults.firstObject;
return result;
}
+ (Price*)fetchPriceInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext {
DataPrice *dataPrice = [self fetchDataPriceInManagedObjectContext:managedObjectContext];
Price *price = [[Price alloc] init];
price.id = dataPrice.id;
price.ron92 = dataPrice.ron92;
price.ron95 = dataPrice.ron95;
price.dieselNormal = dataPrice.dieselNormal;
price.dieselSpecial = dataPrice.dieselSpecial;
price.postDate = dataPrice.postDate;
return price;
}
@end
并完成相同的操作,就像我创建时一样。还有一个点击功能,可以在第一个创建的跨度中正常工作,然后当我清除然后在调整大小后创建完全相同的东西时,它会起作用。
请查看简化的jsfiddle以了解。首先尝试单击对象。然后调整窗口大小并尝试单击它。
http://jsfiddle.net/4159v04o/1/
为什么会出现这种想法?提前谢谢!
答案 0 :(得分:1)
由于div
动态创建/删除。你需要的是event delegation。
事件委托允许我们将单个事件侦听器附加到父元素,该元素将为匹配选择器的所有后代触发,无论这些后代现在是存在还是将来添加。
替换:
$('div').on({click: function() {
使用:
$(document).on("click", "div", function() {
答案 1 :(得分:1)
我调试了代码链接并更改了代码。有一些与名字相关的代码。*。但在名称中只有字符串,而您正在使用不支持的样式方法。
所以我删除了所有名称。*行现在它正常工作
typename std::list<T>::iterator begin() {
return objects.begin();
}
typename std::list<T>::const_iterator begin() const {
// ~~~~^
return objects.begin();
}
typename std::list<T>::const_iterator cbegin() const {
return begin();
}
typename std::list<T>::iterator end() {
return objects.end();
}
typename std::list<T>::const_iterator end() const {
// ~~~~^
return objects.end();
}
typename std::list<T>::const_iterator cend() const {
return end();
}
只需粘贴并运行相同的Jsfiddel示例