使用来自iOS SDk的Loopback定义的数据关系

时间:2014-07-24 17:01:44

标签: javascript loopbackjs strongloop

参考

http://strongloop.com/strongblog/defining-and-mapping-data-relations-with-loopback-connected-models/

如果我已定义客户与订单之间的关系以便订单属于客户,我如何使用iOS SDK从订单中获取客户详细信息?我目前正在使用invokeStaticMethod来获取过滤列表,如下所示:

func getOrders() {
    var prototype: LBModelRepository = adapter.repositoryWithModelName("orders")
    adapter.contract.addItem(SLRESTContractItem(pattern: "/orders", verb: "GET"), forMethod: "orders.filter")
    var params = [
                "filter[where][customerId]": "\(self.customerId)",
                "filter[order]": "startDate DESC"
                ]

    var success: SLSuccessBlock = {
                (results: AnyObject!) in
                    var resultsArray = results as NSArray
                    var resultsMutableArray: NSMutableArray = NSMutableArray()
                    for result: AnyObject in resultsArray {
                        resultsMutableArray.addObject(result as NSDictionary)
                    }
                    self.tableData = resultsMutableArray
                    self.tableView.reloadData()
                }

    var failure: SLFailureBlock = {
                (error: NSError!) -> () in
                }

    prototype.invokeStaticMethod("filter", parameters: params, success: success, failure: failure)
}

是否与调用方法名称为“orders.prototype.customer”的invokeInstanceMethod有关?如何有效地组合通话?

1 个答案:

答案 0 :(得分:0)

您可以使用include参数来嵌入包含的关系。请在http://docs.strongloop.com/display/LB/Include+filter了解更多信息。