簡體   English   中英

Sudzc:如何將參數傳遞給函數?

[英]Sudzc: How to pass arguments or parameters to function?

搜索了很多但無法找到我的查詢的示例。

我已經成功地將sudzc代碼集成到了我的項目中,但是無法找出一種將參數傳遞給函數的方法:

// Returns id
/* Call api functionality */
[service call:self action:@selector(callHandler:) sessionId: @"" resourcePath: @"" args: @"???"];

如果與sudzc合作,有人可以給我示范一個例子。

提前致謝。

我自己想通了。 Sudzc自己沒有提供關於如何將參數傳遞給函數的參考。 我還在互聯網上進行了廣泛的研究,但您找不到任何提示。 因此,不要在這里浪費時間。

該問題的答案是以NSString的形式自己創建過濾器模塊。 在某些帖子中,有人提到我們需要傳遞一個數組。 Sudzc員工尚未實現這一點,老實說,他們無法理解他們想要我們實現自己的目標。

在Magento網站上,我找到了一個SOAP模塊,其中顯示了過濾器參數的結構。

http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.list.html

在鏈接的底部,有給定的soap請求的結構,我在其他任何地方都找不到。 那給了我一個主意。 因此,我編寫了以下函數來生成它們:

-(NSMutableString *)prepareFilter:(NSMutableArray *)items
{
    // Prepare args string
    NSMutableString *s = [NSMutableString string];
    [s appendString:[NSString stringWithFormat:@"<filter SOAP-ENC:arrayType=\"ns1:associativeEntity[%d]\" xsi:type=\"ns1:associativeArray\">", items.count]];

    // Add normal filter
    for (int cnt=0; cnt<items.count; cnt++)
    {
        [s appendString:@"<item xsi:type=\"ns1:associativeEntity\">"];
        [s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Key"]]];
        [s appendString:[NSString stringWithFormat:@"<value xsi:type=\"xsd:string\">%@</value>",[[items objectAtIndex:cnt] objectForKey:@"Value"]]];
        [s appendString:@"</item>"];
    }

    // Closing tag
    [s appendString:@"</filter>"];

    NSLog(@"%@",s);
    return s;
}

-(NSMutableString *)prepareComplexFilter:(NSMutableArray *)items
{
    // Prepare args string
    NSMutableString *s = [NSMutableString string];
    [s appendString:[NSString stringWithFormat:@"<complex_filter SOAP-ENC:arrayType=\"ns1:complexFilter[%d]\" xsi:type=\"ns1:complexFilterArray\">", items.count]];

    // Add complex filter
    for (int cnt=0; cnt<items.count; cnt++)
    {
        [s appendString:@"<item xsi:type=\"ns1:complexFilter\">"];
        [s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Key"]]];
        [s appendString:@"<value xsi:type=\"ns1:associativeEntity\">"];
        [s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Operator"]]];
        [s appendString:[NSString stringWithFormat:@"<value xsi:type=\"xsd:string\">%@</value>",[[items objectAtIndex:cnt] objectForKey:@"Value"]]];
        [s appendString:@"</value>"];
        [s appendString:@"</item>"];
    }

    // Closing tag
    [s appendString:@"</complex_filter>"];

    NSLog(@"%@",s);
    return s;
}

以以下形式將必需的參數傳遞給這些函數:

NSMutableArray *ary_filterNormal = [NSMutableArray arrayWithObjects:
                            [NSDictionary dictionaryWithObjectsAndKeys:@"status",@"Key", @"complete",@"Value", nil],
                            nil];

    [service call:self
           action:@selector(callHandler:)
        sessionId:[USERDEFAULTS objectForKey:@"SESSION"]
     resourcePath:@"sales_order.list"
             args:[self prepareFilter:ary_filterNormal]];

因此,基本上,只需准備請求的結構並將其傳遞給args:進行過濾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM