Angular firebase外键/ ng-repeat

时间:2015-07-20 06:17:59

标签: angularjs firebase crud

我在firebase中有两个表Departamentos - >父母Ciudades - >子的。当我在ng-repeat视图中显示城市时,我需要将$id Departamento替换为Departamentos表中的名称。我该怎么做?

数据库:

database

查看:

<tr ng-repeat="obj in ciudades | filter:search">
 <td>{{obj.idItem}}</td>
 <td>{{obj.nombreCiudad}}</td>
 <td>{{obj.departamentoEciudad }}</td> <-- replace the id to the name located in 'departamentos' table
</tr>

view

2 个答案:

答案 0 :(得分:0)

您需要使用departamentoEciudad对Departamentos表进行另一次查找,然后将其添加到ng-repeat对象

- (void)viewDidLoad {
    [super viewDidLoad];

    [self loadcategoryData];

    SWRevealViewController *revealcontroller = self.revealViewController;
    if (revealcontroller) {
        [self.sideBarbutton setTarget:self.revealViewController];
        [self.sideBarbutton setAction:@selector(revealToggle:)];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }

    // Do any additional setup after loading the view.
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];


    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

}

- (void)viewDidAppear:(BOOL)animated
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}


- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadcategoryData
{
    post = nil;
    NSString *mainurl = [NSString stringWithFormat:@"some url"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    [manager GET:mainurl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        posts = (NSDictionary *)responseObject;
        post = [NSMutableArray array];
        for(NSDictionary *all in posts)
        {
            Categories *category = [Categories new];
            category.title = [all objectForKey:@"catname"];
            category.firsturl = [all objectForKey:@"url"];

            [self.maincollectionView reloadData];
            //call for images

            imagespost = nil;
            NSString *imageUrl = [NSString stringWithFormat:@"%@", category.firsturl];
            AFHTTPRequestOperationManager *managerone = [AFHTTPRequestOperationManager manager];
            [managerone GET:imageUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {



                imagesposts = (NSDictionary *)responseObject;
                NSArray *resultone = [imagesposts objectForKey:@"posts"];
                imagespost = [NSMutableArray array];
                if ([resultone count]) {
                    NSDictionary *firstpost = resultone[0];
//                    Categories *newmogocat = [Categories new];


                    NSDictionary *thumbnail_images = [firstpost objectForKeyedSubscript:@"thumbnail_images"];
                    NSDictionary *thumbnail = [thumbnail_images objectForKey:@"thumbnail"];
                    category.imageOneUrl = [NSString stringWithFormat:@"%@",[thumbnail objectForKey:@"url"]];
//                    NSLog(@"%@", newmogocat.imageOneUrl);
//                    [imagespost addObject:newmogocat];

                    [post addObject:category];

                    [self.maincollectionView reloadData];
                }

            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//                
//                UIAlertView *erroralert = [[UIAlertView alloc] initWithTitle:@"Something Wrong!" message:[NSString stringWithFormat:@"%@", error.localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
//                [erroralert show];

            }];


        }

    } failure:^(AFHTTPRequestOperation *operation, NSError * responseObject) {

    }];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [post count];
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CategoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellidentifier" forIndexPath:indexPath];
//    cell.layer.borderWidth = 2.0f;
    cell.layer.masksToBounds = NO;
    cell.layer.cornerRadius = 5.0;
    cell.layer.borderColor = [UIColor lightGrayColor].CGColor;
    cell.layer.shadowOffset = CGSizeMake(0, 1);
    cell.layer.shadowRadius = 4.0;
    cell.layer.shadowColor = [UIColor darkGrayColor].CGColor;


    [cell addSubview:cell.maintitleLabel];

    Categories *cat = [post objectAtIndex:indexPath.row];
    [self.maincollectionView reloadInputViews];
    cell.maintitleLabel.text = [NSString stringWithFormat:@" %@ ", cat.title];
    [cell.maintitleLabel sizeToFit];






    NSString *mainstring = [NSString stringWithFormat:@"%@", cat.imageOneUrl];
    NSURL *url = [NSURL URLWithString:mainstring];
//
    [cell.mainImageView setImageWithURL:url placeholderImage:nil];
//



    return cell;
}

答案 1 :(得分:0)

我很高兴因为这个拦截器已经解决了,我做到了:

我在数据库中添加了一个名为-nombreDepartamento的新字段,当控制器以foreach开头时,我执行查询以取代$ id by departamentos.nombre:)

"yyyy-MM-dd H:m:s"