在Sencha Touch中将存储数据编码为JSON字符串

时间:2022-01-21 16:44:28

I'm trying to make a simple Sencha Touch App that submits a form with attached images, and stores the data in a remote MySQL database via PHP.

我正在尝试制作一个简单的Sencha Touch应用程序,它提交带有附加图像的表单,并通过PHP将数据存储在远程MySQL数据库中。

The user-inserted images are stored in a data store.

用户插入的图像存储在数据存储中。

When the user clicks the submit button, I would like all the data in the store to be encoded into a JSON string which I can easily send to my database.

当用户单击提交按钮时,我希望将商店中的所有数据编码为JSON字符串,我可以轻松地将其发送到我的数据库。

Is there any way to do this in Sencha Touch?

在Sencha Touch有什么办法吗?

Thanks!

谢谢!

2 个解决方案

#1


1  

Sencha Touch has the JSON lib included, you can encode in the following manner:

Sencha Touch包含JSON lib,您可以通过以下方式进行编码:

Ext.util.JSON.encode(formDataArray)

Also have a look at the Sencha Touch API Docs here: http://docs.sencha.com/touch/1-1/#!/api/Ext.util.JSON which references http://www.json.org/js.html

另请参阅这里的Sencha Touch API文档:http://docs.sencha.com/touch/1-1/#!/api/Ext.util.JSON,其中引用了http://www.json.org/ js.html

#2


0  

You can encode image to Base64 string and when attached to your form you can store base64 string value in a hidden field in your form.

您可以将图像编码为Base64字符串,当附加到表单时,您可以将base64字符串值存储在表单的隐藏字段中。

When user clicks submit button you retrieve values in your form using activePanel.getValues(false).This gives you JSON presentation of components you used in your form and their values.

当用户单击“提交”按钮时,您将使用activePanel.getValues(false)检索表单中的值。这将为您提供表单中使用的组件及其值的JSON表示。

#1


1  

Sencha Touch has the JSON lib included, you can encode in the following manner:

Sencha Touch包含JSON lib,您可以通过以下方式进行编码:

Ext.util.JSON.encode(formDataArray)

Also have a look at the Sencha Touch API Docs here: http://docs.sencha.com/touch/1-1/#!/api/Ext.util.JSON which references http://www.json.org/js.html

另请参阅这里的Sencha Touch API文档:http://docs.sencha.com/touch/1-1/#!/api/Ext.util.JSON,其中引用了http://www.json.org/ js.html

#2


0  

You can encode image to Base64 string and when attached to your form you can store base64 string value in a hidden field in your form.

您可以将图像编码为Base64字符串,当附加到表单时,您可以将base64字符串值存储在表单的隐藏字段中。

When user clicks submit button you retrieve values in your form using activePanel.getValues(false).This gives you JSON presentation of components you used in your form and their values.

当用户单击“提交”按钮时,您将使用activePanel.getValues(false)检索表单中的值。这将为您提供表单中使用的组件及其值的JSON表示。