【问题标题】:How to use Relationship to retrieve image on Parse Server using swift如何使用关系在 Parse Server 上使用 swift 检索图像
【发布时间】:2016-09-29 00:00:32
【问题描述】:

新解析,我浏览了文档但我没有掌握关系的概念......

我有一个一对多的关系(产品 -> 许多颜色变化)。

解析时,在我的“产品”类下,我有以下列: 品牌、尺寸、价格、颜色。

颜色单元是与“颜色”类挂钩的关系,其中包含: Color_Name、Color_Image(作为文件)。

如何访问 color_name 和 color_image?我正在使用下面的代码,但返回 nil。

func searchCategoryItems(){

categoryType = "basketball"

let query:PFQuery = PFQuery(className: "products")
                query.includeKey("color")
                let productQuery = query.whereKey("type", equalTo:self.categoryType)

                productQuery.findObjectsInBackgroundWithBlock {
                    (objects, error) -> Void in

                    for object in objects! {
                        let brandName:String? = (object as PFObject)["brand"] as? String
                        let itemName:String? = (object as PFObject)["item_name"] as? String
                        let sku:String? = (object.objectId! as String)
                        let colors:String? = (object as PFObject)["color_name"] as? String
                        if colors != nil{
                        self.productColorArray.append(colors!)
                        print("colors work?", colors)
                        }

                        if brandName != nil {
                            self.productBrandArray.append(brandName!)
                        }
                        if itemName != nil{
                            self.productItemNameArray.append(itemName!)
                        }
                        if sku != nil{
                            self.productSkuArray.append(sku!)
                        }


                    }

                    self.searchTableView.reloadData()
                }
                self.searchTableView.insertRowsAtIndexPaths([NSIndexPath(forRow:0,inSection:0)], withRowAnimation: UITableViewRowAnimation.Automatic)
            }
    }

这就是我的解析仪表板的设置:

【问题讨论】:

    标签: swift parse-platform parse-server pfquery


    【解决方案1】:

    您需要执行额外的关系查询。

    let product = ...//specify a product. e.g. object in objects
    let relation = product.relationForKey("color")
    let innerQuery = relation.query()
    //then executing the innerQuery
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多