【问题标题】:Sitecore Mobile SDK: how to read the value from a linkedItem in a DropLinkSitecore Mobile SDK:如何从 DropLink 中的 linkedItem 读取值
【发布时间】:2013-08-20 19:34:04
【问题描述】:

我正在使用 Sitecore Mobile SDK 创建本机 IOS 应用程序。到目前为止,我能够读取我需要的项目,但我一直无法从 Droplink 字段中的链接项目中读取字段值。

我使用这个代码:

SCApiContext* context = [SCApiContext contextWithHost: @"http://<myhost>/-/item"];
SCItemsReaderRequest* request = [ SCItemsReaderRequest new ];
request.requestType = SCItemReaderRequestQuery;
request.request = @"/sitecore/content/Home/descendant::*[@@templatename='Content item']";
request.flags = SCItemReaderRequestReadFieldsValues;
request.fieldNames = [ NSSet setWithObjects: @"Content title", @"Content author", @"Content introduction", @"Content date", @"Content body" , nil ];

    [context itemsReaderWithRequest: request]( ^(id result, NSError* error)
    {
        NSArray* items = result;

        for (SCItem* item in result)
        {
            // get the author
            __block NSString *author = @"empty";
            SCField *dropLinkField = [item fieldWithName: @"Content author"];

            [dropLinkField fieldValueReader]( ^(id result, NSError *error)
            {
                if (!error)
                {
                    SCItem *linkedItem = result;

                    // TODO: author is not yet filled
                    NSSet *fieldsSet = [NSSet setWithObjects:@"Firstname", nil];
                    // this method seems to be skipped
                    [linkedItem fieldsReaderForFieldsNames:fieldsSet]( ^(id result2, NSError *error2)
                       {
                           if (!error2)
                           {
                               NSDictionary *fields = result2;
                               SCField *field_ = [fields objectForKey: @"Firstname"];
                               author = field_.rawValue;
                           }
                       });
                }
            });


        }

    }

原始项目被读取,我可以读取droplink字段的字段值。似乎我也可以读取链接的项目,因为我可以将它的项目路径写入日志。但是当我尝试从链接项中读取字段时,它会失败,并且似乎跳过了“fieldsReaderForFieldsNames”方法。

我显然在这里做错了什么,但似乎忽略了这个问题......

编辑:

我忘了提到我使用的是 Sitecore 7,不确定它是否会有所作为。 我添加了上面创建 SCApiContext 和 SCItemReaderRequest 的行。

我使用匿名访问并在“站点设置”中使用

itemwebapi.mode="StandardSecurity" 
itemwebapi.access="ReadOnly" 
itemwebapi.allowanonymousaccess="true"

我只是认为我找到了问题,因为我没有在几个字段上设置字段远程读取权限。但是,设置该权限并没有解决它,并且没有设置字段远程读取的其他字段确实在 API 中返回。

【问题讨论】:

  • 1.你在使用匿名上下文吗?您是作为“sitecore”还是“extranet”用户进行身份验证? 2. 能否附上创建 SCApiContext 和 SCItemsReaderRequest 的代码? 3. 您的 ItemWebAPI.config 的“站点”设置是什么?通常,它位于“C:\inetpub\wwwroot\ Your_Site \Website\App_Config\Include” 4. 请确保您已授予您正在尝试的项目的 Read、FieldRead 和 RemoteFieldRead 权限访问。请使用 Access Viewer 进行检查。 Sitecore iOS SDK 将所有 Item Web API HTTP 请求写入日志。你能附上这些吗?

标签: objective-c sitecore sitecore6 sitecore-mobile-sdk


【解决方案1】:

Sitecore iOS SDK 操作(来自下面的列表)在后台操作队列上异步执行。
* 字段值读取器
* fieldsReaderForFieldsNames

这不保证在您访问作者数据时已下载。

请在完成回调块中使用下载的项目和字段,以确保它们存在于您的 iPhone 上。

[linkedItem fieldsReaderForFieldsNames:fieldsSet]( ^(id result2, NSError *error2)
{
    NSLog(@"Read author field");
    if (!error2)
    {
    NSLog(@"No error");
    NSDictionary *fields = result2;
    SCField *field_ = [fields objectForKey: @"Firstname"];
    author = field_.rawValue;

    // Now all required fields will 
    // definitely be downloaded by the time you create a blog item


    NSLog(@"voornaam: %@", author);

    ParTechBlogItem *blogItem;
    blogItem = [[ParTechBlogItem alloc] initWithTitle:[item fieldValueWithName:@"Content title"] 
                                                 date:[item fieldValueWithName:@"Content date"] 
                                                intro:[item fieldValueWithName:@"Content introduction"] 
                                               author:author 
                                                 text:[item fieldValueWithName:@"Content body" ]];
        [weakSelf addBlogItem:blogItem];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多