【问题标题】:Handling multiple records and models trought ajax in a form using Yii使用 Yii 在表单中处理多个记录和模型 ajax
【发布时间】:2012-05-28 12:53:24
【问题描述】:

这一定是一种常见的情况:

在一个名为 Subscription 的表单上,除了其他与订阅相关的字段外,我们还有:

选择您需要多少 foo选择框有 5 个选项,从 [1] 到 [5]

如果用户选择 2,那么通过 Ajax 应该会出现以下内容:

<!-- for 1 -->
 <input type="text" id="name1">Name of thing</input>  
 <input type="text" id="age1">Age of thing</input>  

<!-- for 2 -->
 <input type="text" id="name2">Name of thing</input>  
 <input type="text" id="age2">Age of thing</input> 

所以,我们有两个表(Subscription,foo),要在其中一个表(foo)上插入几条记录,所有这些都在一个表单上。

有没有人好心地画一个简单的例子来说明我们应该如何正确处理上述情况?

我发现的更接近的是这个,但是,它不涵盖多个模型或 ajax。 :/ http://www.yiiframework.com/doc/guide/1.1/en/form.table

真的希望有人可以在这里推动我。

【问题讨论】:

    标签: design-patterns yii multiple-records


    【解决方案1】:

    请看Yii 1.1 Application Development Cookbook

    一书中的Handling variable number of inputs章节

    【讨论】:

      【解决方案2】:

      我目前正在努力解决模拟问题。 一般来说,我认为您应该能够遍历模型。每个表单都有如下字段名称:Object[$i]['number'] ($i = counter)。我认为,ajax 请求可以是部分渲染,不是吗?

      如果我今晚找到它,我会在这里发布一些代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-15
        • 1970-01-01
        • 2012-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多