简体   繁体   English

无法将数据从json填充到extjs 4中的表单

[英]Unable to populate data from json to form in extjs 4

I have created a form panel and would like to populate json data into form. 我创建了一个表单面板,并希望将json数据填充到表单中。

I am sending url from tastypie. 我正在发送来自sweetpie的网址。

{"EmailAddress": "aaaaa@gmail.com", "FirstName": "bbbbb", "HomePhone": "23333","resource_uri": "/api/xxxx/1/"}

Name of my form panel is formPanel. 我的表单面板的名称是formPanel。

When I am trying to run below the data is not populating by showing error. 当我尝试在下面运行时,数据不会因显示错误而填充。

formPanel.getForm().load({
        method : 'GET',
                url : '/api/xxx/1/?format=json',
                });

Can any one please help me to load form. 谁能帮我加载表格。

@sreekanth, it is possible to load JSON data directly into a form (if the situation really calls for it). @sreekanth,可以将JSON数据直接加载到表单中(如果情况确实需要)。 Take a look at the docs for Ext.form.action.Load . 看一下Ext.form.action.Load的文档。 I'm not familiar with the tastypie API, but I suspect that the JSON response may not be exactly what ExtJS expects. 我不熟悉freshpie API,但我怀疑JSON响应可能与ExtJS期望的不完全相同。 From the ExtJS documentation: 从ExtJS文档中:

Response Packet Criteria 响应数据包标准

A response packet must contain: 响应数据包必须包含:

  • success property : Boolean 成功属性:布尔值
  • data property : Object 数据属性:对象

The data property contains the values of Fields to load. data属性包含要加载的字段的值。 The individual value object for each Field is passed to the Field's setValue method. 每个字段的单个值对象将传递到字段的setValue方法。

All that said, @sha's suggestion is a good one: Getting familiar with the Store and Model objects in ExtJS will save you time and trouble in the long run. 综上所述,@ sha的建议是一个很好的建议:长期使用ExtJS中的Store和Model对象将为您节省时间和麻烦。

I think you need read about ExtJs concepts for Stores and Models. 我认为您需要阅读有关商店和模型的ExtJs概念。 You don't just load JSON object into ExtJs form. 您不只是将JSON对象加载到ExtJs表单中。 You actually need to create a store, load records to this store and load particular record into form. 实际上,您实际上需要创建一个商店,将记录加载到该商店并将特定记录加载到表单中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM