简体   繁体   English

Sudzc:如何将参数传递给函数?

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

Have searched a lot but am unable to find an example for my query. 搜索了很多但无法找到我的查询的示例。

I have successfully integrated sudzc code into my project but am not able to figure out a way to pass arguments to the function: 我已经成功地将sudzc代码集成到了我的项目中,但是无法找出一种将参数传递给函数的方法:

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

Can someone please show me a way with an example if worked with sudzc. 如果与sudzc合作,有人可以给我示范一个例子。

Thanks in advance. 提前致谢。

I figured it myself. 我自己想通了。 There is not reference given by Sudzc themselves, as to how pass arguments to the functions. Sudzc自己没有提供关于如何将参数传递给函数的参考。 I also did extensive research on the internet, but you wont find any hint. 我还在互联网上进行了广泛的研究,但您找不到任何提示。 So don't waste your time there. 因此,不要在这里浪费时间。

The answer to this issue is to create the filter module yourself in the form of an NSString. 该问题的答案是以NSString的形式自己创建过滤器模块。 In some posts, somebody mentioned that we need to pass an array. 在某些帖子中,有人提到我们需要传递一个数组。 That's something that Sudzc people have not implemented yet and to be honest wasn't able to understand what they wanted us to implement ourselves. Sudzc员工尚未实现这一点,老实说,他们无法理解他们想要我们实现自己的目标。

From the site of Magento, I found a module of SOAP where it shows the structure of filter arguments. 在Magento网站上,我找到了一个SOAP模块,其中显示了过滤器参数的结构。

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

At the bottom of the link, there is the structure for the soap request given, which I didn't find anywhere else. 在链接的底部,有给定的soap请求的结构,我在其他任何地方都找不到。 That gave me an idea. 那给了我一个主意。 So I wrote the following functions for generating them: 因此,我编写了以下函数来生成它们:

-(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;
}

Pass required arguments to these functions in this form: 以以下形式将必需的参数传递给这些函数:

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]];

So basically just prepare the structure of the request and pass it to the args: for filtering. 因此,基本上,只需准备请求的结构并将其传递给args:进行过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM