将嵌套表单数据保存回ExtJS中的服务器 [英] Save nested form data back to server in ExtJS

查看:121
本文介绍了将嵌套表单数据保存回ExtJS中的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含与另一个模型的关联的模型。我可以通过使用该字段上的映射属性将嵌套数据显示到表单中。示例:

  Ext.define('Example.model.Request',{
extends:'Ext.data。模型',

字段:[
{
名称:'id',
类型:Ext.data.Types.NUMBER,
useNull:false
}
{
名称:'plan_surveyor',
映射:'plan.surveyor',
类型:Ext.data.Types.STRING
}


关联:[
{type:'hasOne',associationKey:'plan',getterName:'getPlan',model:'Specs.model.Plan'}
],

proxy:{
type:'direct',
api:{
read:requestController.load,
update: requestController.update,
},
reader:{
type:'json',
root:'records'
},
writ呃:{
type:'json',
writeAllFields:true,
nameProperty:'mapping'
}
}

}) ;

使用此方法,可以通过引用plan_surveyor在表单中显示plan.surveyor值。我调用Form.loadRecord(model)将数据从模型中拉入到表单中。



但是,现在我试图将数据发送回服务器,我收到错误:



执行操作时出错。请报告以下内容:无法识别的字段plan.surveyor



我试图通过首先调用Form.updateRecord模型),然后是model.save()。有没有办法让Writer了解plan.surveyor不是属性名称,而是正确处理嵌套?



我正在做这个开始的正确方法,还是应该正式处理表单数据的设置,并以更为手工的方式加载到模型中?似乎嵌套数据一般不是很好的支持 - 任何建议?

解决方案

  Ext.define('Example.model.Request' {
extends:'Ext.data.Model',

fields:[
{
name:'id',
type:Ext.data .Types.NUMBER,
useNull:false
}
{
name:'plan_surveyor',
映射:'plan.surveyor',//更改为'plan_surveyor'
类型:Ext.data.Types.STRING
}
],

更改在评论中显示,因为数据索引以上述格式给出,因为ur给出的url格式是不是dataindex的时间它是一列或者extjs的准备,所以请更改,这可能是很好的



它不工作你将发送孔代码


I have a Model that contains an association to another Model. I am able to display the nested data into a form by using the mapping attribute on the field. Example:

Ext.define('Example.model.Request', {
    extend: 'Ext.data.Model',

    fields: [
        {
            name: 'id',
            type: Ext.data.Types.NUMBER,
            useNull: false
        }
        {
            name: 'plan_surveyor',
            mapping: 'plan.surveyor',
            type: Ext.data.Types.STRING
        }
    ],

    associations: [
               {type: 'hasOne', associationKey: 'plan', getterName:'getPlan', model: 'Specs.model.Plan'}
              ],

    proxy: {
            type: 'direct',
            api: {
                read: requestController.load,
                 update: requestController.update,
            },
            reader: {
                type: 'json',
                root: 'records'
            },
            writer: {
                type: 'json',
                writeAllFields: true,
                nameProperty: 'mapping'
            }
        }

    });

Using this method, I can display the plan.surveyor value in the form by reference plan_surveyor. I call Form.loadRecord(model) to pull the data from the model into the form.

However, now that I'm trying to send the data back to the server, I get the error:

Error performing action. Please report the following: "Unrecognized field "plan.surveyor"

I am attempting to save to the server by first calling Form.updateRecord(model), then model.save(). Is there a way to have the Writer understand that 'plan.surveyor' is not a property name but instead to properly handle nesting?

Am I doing this the right way to start with, or should I just be handling the setting of the form data and loading back into the model in a more manual fashion? It seems that nested data is not all that well supported in general - any recommendations?

解决方案

    Ext.define('Example.model.Request', {
        extend: 'Ext.data.Model',

        fields: [
            {
                name: 'id',
                type: Ext.data.Types.NUMBER,
                useNull: false
            }
            {
                name: 'plan_surveyor',
                mapping: 'plan.surveyor',//change to 'plan_surveyor'
                type: Ext.data.Types.STRING
            }
        ],

change that show in comment ,because data index is given in above format because ur give ur format thata time that is not dataindex it's a column or extjs preparatory ,so please change that may it's work well

it's not work u will send hole code

这篇关于将嵌套表单数据保存回ExtJS中的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆