1

所以我有这个表单,它推送一个用于收集邮寄地址信息的子表单(为了清楚起见,我在此处简化了表单的 JSON 定义 - 我确实测试了这个版本,但它仍然中断):

{
    "grouped": true,
    "title": "Add",
    "sections": [
                 { "elements":[
                               { "type":"QLabelElement", "title":"Location",
                               "sections": [
                                            {
                                             "elements": [ { "type":"QEntryElement", "title":"Address line 1","placeholder":"", "bind":"textValue:Address1", "key":"Address1"},
                                                         { "type":"QEntryElement", "title":"Address line 2","placeholder":"optional", "bind":"textValue:Address2", "key":"Address2"},
                                                         { "type":"QEntryElement", "title":"City","placeholder":"", "bind":"textValue:City", "key":"City"},
                                                         { "type":"QEntryElement", "title":"State/Province","placeholder":"", "bind":"textValue:StateProvRegion", "key":"Prov"},
                                                         { "type":"QEntryElement", "title":"ZIP/Postal Code","placeholder":"", "bind":"textValue:PostalCode", "key":"PCode"},
                                                         { "type":"QPickerElement", "title":"Country", "items":[["Czech Republic", "Germany", "United Kingdom"]], "value":"Czech Republic"}
                                                         ]
                                            }]
                               }
                               ]
                 }
                 ]
}

我有一个 NSMutableDictionary ,其中包含一堆数据,可以预先弹出表单中的所有字段,包括地址中的字段。填充字典并显示对话框的代码如下所示(再次,超级简化,但这仍然中断):

NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];

[dataDict setObject:@"123 Maple Street" forKey:@"Address1"];

QRootElement *root = [[QRootElement alloc] initWithJSONFile:@"addjobform" andData:dataDict];

UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];

如果我使用上面的 JSON 运行此代码,对话框会正常显示,但不会填充字段。但是 -如果我将地址元素从嵌套子表单中移回第一级- 它们会填充(在这种情况下,Address1 会预先弹出 123 Maple Street)。换句话说,这个 JSON 正确绑定,而上面的先前版本没有:

{
    "grouped": true,
    "title": "Add",
    "sections": [{
                 "elements": [ { "type":"QEntryElement", "title":"Address line 1","placeholder":"", "bind":"textValue:Address1", "key":"Address1"},
                              { "type":"QEntryElement", "title":"Address line 2","placeholder":"optional", "bind":"textValue:Address2", "key":"Address2"},
                              { "type":"QEntryElement", "title":"City","placeholder":"", "bind":"textValue:City", "key":"City"},
                              { "type":"QEntryElement", "title":"State/Province","placeholder":"", "bind":"textValue:StateProvRegion", "key":"Prov"},
                              { "type":"QEntryElement", "title":"ZIP/Postal Code","placeholder":"", "bind":"textValue:PostalCode", "key":"PCode"},
                              { "type":"QPickerElement", "title":"Country", "items":[["Czech Republic", "Germany", "United Kingdom"]], "value":"Czech Republic"}
                              ]
                 }
                 ]
}

为什么绑定在第一级起作用,而不是嵌套在 Location 标签下?表单推送按广告宣传,但绑定已损坏 - 我有什么特别的事情要做吗?我进行了广泛搜索,但没有找到答案或示例。我在一个精简的单视图应用程序中尝试了此代码,该应用程序只执行上述操作,但它仍然中断 - 所以它也不是与我的其他代码的交互。根据 QuickDialog 的作者,应该支持子表单嵌套(https://github.com/escoz/QuickDialog/issues/226)有什么想法吗?谢谢!

4

1 回答 1

0

默认情况下,QuickDialog 执行所谓的“浅”绑定,其中只有第一级元素被绑定。这很有帮助,因为您可以控制表单何时更新,而无需将每个表单定义为不同的 JSON 文件。

每个 QElement 都有一个shallowBind默认为 YES 的属性。如果将其更改为 no,则绑定将持续到下一层。因此,在您的情况下,您想要告诉 QuickDialog QLabelElement 不应遵循浅绑定,例如:

{"type":"QLabelElement", "shallowBind":false, "title":"Location", ...

这告诉父部分,当它绑定到一个对象时,它也应该进入这个元素。

于 2014-04-10T15:46:36.473 回答