在Zend Framework 2应用程序中的表单集合中使用dgrid

时间:2023-01-16 19:34:08

For our new project, we have started using Zend Framework 2 and Dojo 1.8. ZF2 has a completely rewritten form module, which now features the new CollectionElement for one-to-many relationships. Regarding UI I find, that dgrid fits best for such relationships (using the editor column plugin), so I started extending FormCollection, FormRow and FormElement view helpers, so they can render the desired dgrid. Everything was fine until I realized, that I cannot set per-row input names for the dgrid widgets.

对于我们的新项目,我们已经开始使用Zend Framework 2和Dojo 1.8。 ZF2有一个完全重写的表单模块,现在它具有一对多关系的新CollectionElement。关于UI我发现,dgrid最适合这种关系(使用编辑器列插件),所以我开始扩展FormCollection,FormRow和FormElement视图助手,这样他们就可以渲染所需的dgrid。一切都很好,直到我意识到,我不能为dgrid小部件设置每行输入名称。

I started with the ZF2 documentation rearding form collections. One can see, that collection input elements have array-like names like

我开始使用ZF2文档来修改表单集合。可以看到,集合输入元素具有类似数组的名称

order[products][0][name]
order[products][0][price]
order[products][1][name]
order[products][1][price]

On the other hand, dgrid's configuration is column based, so I can have a column definition like

另一方面,dgrid的配置是基于列的,所以我可以有一个列定义

editor({
    field: "_dojo_textbox_505ee3a390d705_26717315", 
    label: "Name",
    editorArgs: {
        name: "order[products][{index}][name]",
    }
}, TextBox)

This column definition will define set the same widget name for all rows, which does not work with the ZF2 collection data format requirement.

此列定义将为所有行定义相同的窗口小部件名称,这不适用于ZF2集合数据格式要求。

What I also tried is naming the column like this:

我也尝试过这样命名列:

order[products][]

which works, but does not allow the desired format

哪个有效,但不允许所需的格式

order[products][][name]

Maybe there is a way to post the data like this:

也许有办法发布这样的数据:

order[products][name][]

and have it converted afterwards, but the solution doesn't looks right. Beside this I am trying to produce reusable code and want to avoid per-form data modifications.

然后让它转换,但解决方案看起来不正确。除此之外,我试图生成可重用的代码,并希望避免每个表单的数据修改。

Since I am trying very hard to avoid onSubmit/onClick event handling for data conversion, there are 2 possible solutions: 1. Make dgrid able to set per-row widget names 2. Make ZF2 form understand some other-than-standard POST format for collections

由于我非常努力避免onSubmit / onClick事件处理进行数据转换,因此有两种可能的解决方案:1。使dgrid能够设置每行小部件名称2.使ZF2表单理解一些非标准的POST格式集合

Unfortunately I ran out of ideas, how either of those solutions can be done, so I will be most thankful, if you can give me a hand with this!

不幸的是,我没有想法,这些解决方案是如何完成的,所以如果你能帮我解决这个问题,我将非常感激!

Since this is somewhat related with my current question, I will place it here as a side question: What other than this UI solution do you use for your one-to-many form interfaces with dojo?

由于这与我当前的问题有些相关,我将把它放在这里作为一个侧面问题:除了这个UI解决方案,你还使用什么来实现与dojo的一对多表单接口?

1 个解决方案

#1


1  

In Zend framework version 2 , "Zend\Form" itself has the capability to add new elements to the "Collection element" dynamically.

在Zend框架版本2中,“Zend \ Form”本身具有动态地向“Collection元素”添加新元素的能力。

You can check it here

你可以在这里查看

#1


1  

In Zend framework version 2 , "Zend\Form" itself has the capability to add new elements to the "Collection element" dynamically.

在Zend框架版本2中,“Zend \ Form”本身具有动态地向“Collection元素”添加新元素的能力。

You can check it here

你可以在这里查看