iOS上的QuickDialog不绑定到JSON中的子表单元素

时间:2014-04-10 03:15:20

标签: ios json quickdialog

所以我有这个表单,它推送一个子表单来收集邮件地址信息(为了清楚起见,我在这里简化了表单的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)任何想法?谢谢!

1 个答案:

答案 0 :(得分:0)

默认情况下,QuickDialog执行的操作是"浅"绑定,只有第一级元素绑定。这很有用,因为您可以控制表单何时更新,而无需将每个表单定义为不同的JSON文件。

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

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

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