Backbone更新嵌套属性

时间:2015-12-17 09:55:57

标签: javascript backbone.js

我有一个表格,显示的模型集合大致如下:

data

我可以从表格中选择一个模型,并在模态中对其属性进行编辑。编辑完属性后,我调用save,关闭模态并传递一个事件来刷新我的表。在我的表格视图中,我收到了一个活动,并使用- (void)upload { AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate]; // *** Set background task accordingly *** [appDel setApplicationObj:[UIApplication sharedApplication]]; [appDel setBgTask:[[appDel applicationObj] beginBackgroundTaskWithExpirationHandler:^{ [[appDel applicationObj] endBackgroundTask:[APP_DEL bgTask]]; [appDel setBgTask:UIBackgroundTaskInvalid]; }]]; // *** Begin file upload task to Amazon *** dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ // File upload task . @try { // *** Initialize AmazonS3Client object using AccessKey and SecretKey *** AmazonS3Client *objAmazonS3 = [[AmazonS3Client alloc] initWithAccessKey:@"<Access Key>" withSecretKey:@"<Secret Key>"]; objAmazonS3.endpoint = [AmazonEndpoints s3Endpoint:US_EAST_1]; // *** Initialize S3PutObjectRequest with filename & bucket in which to drop it. *** S3PutObjectRequest *objS3PutRequest = [[S3PutObjectRequest alloc] initWithKey:@"MyFile.txt" inBucket:@"<Bucket Name>"]; // *** Set content type according to your file type, here its plain text **** [objS3PutRequest setContentType:@"text/plain"]; // *** set NSData of your File, here i am converting String into NSData *** NSData *data = [@"This is my sample text" dataUsingEncoding:NSUTF8StringEncoding]; [objS3PutRequest setData:data]; // *** Its optional *** [objS3PutRequest setRequestTag:@"fileUpload"]; // *** Start upload task by putting request *** [objAmazonS3 putObject:objS3PutRequest]; // *** Register upload callback, when it finishes upload it will invoke following method *** [self performSelectorOnMainThread:@selector(fileUploadCallback) withObject:nil waitUntilDone:NO]; } @catch (AmazonClientException *exception) { NSLog(@"File Upload Failed, Reason: %@", exception); } }); } - (void)fileUploadCallback { NSLog(@"Upload complete."); }

致电{ id: 1, name: "Product", category: { id: 1, name: "CategoryName" }, { id: 2, name: "Another Product", category: { id: 1, name: "CategoryName" }, etc..
fetch

但是,在没有硬刷新的情况下,嵌套属性(在本例中为update: true)都不会更新。我怎么解决这个问题?谢谢!

1 个答案:

答案 0 :(得分:2)

尝试传递reset:true作为提取

的选项
App.vent.on("refresh:products", function() {
    return this.collection.fetch()({
        reset: true
    });
});

这将阻止主干合并从服务器收到的数据。

相关问题