在 Ext-js 中插入后将记录保存在网格中

发布于 2024-12-11 06:07:55 字数 663 浏览 0 评论 0原文

我有带有商店的网格,我将记录添加到商店,并且添加到商店的数据会反映在网格上。但是刷新后它就会消失。

这是我插入记录的代码

handler: function() {

    grid.getStore().insert(
        0,
        new ds_model({
            id:0,
            name:'',
            dob:''
        })
    );

    grid.startEditing(0,0);
    grid.store.commitChanges();

    } 
}) 

编辑:

var store = new Ext.data.Store({
    data: [
        [ 11849,'ABC','29/03/90'],
        [ 11456,'CDE','17/03/90'],
        [ 11344,'EFG','17/07/90'],
        [ 11343,'IJK','Trainee','02/06/90'],
...

I have grid with store and i add the record to the store and data being added to the store gets reflected on the grid.but after refresh it vanishes.

here is my code for inserting the record

handler: function() {

    grid.getStore().insert(
        0,
        new ds_model({
            id:0,
            name:'',
            dob:''
        })
    );

    grid.startEditing(0,0);
    grid.store.commitChanges();

    } 
}) 

EDIT:

var store = new Ext.data.Store({
    data: [
        [ 11849,'ABC','29/03/90'],
        [ 11456,'CDE','17/03/90'],
        [ 11344,'EFG','17/07/90'],
        [ 11343,'IJK','Trainee','02/06/90'],
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧人哭 2024-12-18 06:07:55

您还需要结束编辑,否则商店无法提交任何更改。使用 firebug 检查您的商店是否正在保存。您还可以使用 autosave: TRUE 来保存提交

You need to end your editing also otherwise there are no changes the store can commit. use firebug to check, that your store is saving. You also may use autosave: TRUE to spare the commit

意犹 2024-12-18 06:07:55

根据您在最初问题中的评论,您将商店定义如下:

    new Ext.data.Store({
        data: [
            [ 11849,'ABC','29/03/90'],
            [ 11456,'CDE','17/03/90'],
            [ 11344,'EFG','17/07/90'],
            [ 11343,'IJK','Trainee','02/06/90']
        ]
    });

这不会设置任何自动持久保存到任何后端服务器。此外,您将数据硬编码到存储中,这意味着当您重新加载时,实际上每次都会将该数据放入存储中。为了方便保存和加载到后端/从后端加载,您只需按如下方式修改它:

    new Ext.data.Store({
        autoSync: true,  // this will tell Ext to persist your changes
                         // to the backend when you change an entry in the store
        autoLoad: true,  // this will tell Ext to load the store with data from
                         // the backend
        url: // put your url to save
    });

另请注意,您将需要一个 url 来期望从此调用。这很可能是一个 php 文件。根据您在网格中插入的内容,您将需要在 php 文件中添加如下内容:

myFile.php
==========

    <?php
        $id = $_POST['id'];  // get id from client
        $name = $_POST['name'];  // get name from client
        $dob = $_POST['dob'];  // get date of birth from client

        // do any saving of this data, e.g, to your database here
    ?>

此外,您还需要一个 php 文件来加载商店。

阅读此内容以获得更多说明。

As per your comments in the initial question, you defined your store as follows:

    new Ext.data.Store({
        data: [
            [ 11849,'ABC','29/03/90'],
            [ 11456,'CDE','17/03/90'],
            [ 11344,'EFG','17/07/90'],
            [ 11343,'IJK','Trainee','02/06/90']
        ]
    });

This will not set up any automatic persisting to any backend server. Also, you are hard-coding data into the store, which means that when you reload, you are literally putting that data in the store every time. To make it easy to save and load to/from backend, you just need to modify it as such:

    new Ext.data.Store({
        autoSync: true,  // this will tell Ext to persist your changes
                         // to the backend when you change an entry in the store
        autoLoad: true,  // this will tell Ext to load the store with data from
                         // the backend
        url: // put your url to save
    });

Also note that you will need a url that will expect a call from this. This will most likely be a php file. Based on what you are inserting in the grid, you will need something like this in a php file:

myFile.php
==========

    <?php
        $id = $_POST['id'];  // get id from client
        $name = $_POST['name'];  // get name from client
        $dob = $_POST['dob'];  // get date of birth from client

        // do any saving of this data, e.g, to your database here
    ?>

Also, you'll need a php file that will do the loading of the store.

Read this and this for more clarification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文