Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php extjs4:可编辑网格不';t提交对MySQL数据库的更改_Php_Mysql_Extjs_Extjs4 - Fatal编程技术网

Php extjs4:可编辑网格不';t提交对MySQL数据库的更改

Php extjs4:可编辑网格不';t提交对MySQL数据库的更改,php,mysql,extjs,extjs4,Php,Mysql,Extjs,Extjs4,亲爱的EXT爱好者们: 我正在做一个项目,我需要一个管理面板来编辑工作职能。 网格正在使用Ext.Direct与MySQL数据库通信。它可以很好地加载数据。 网格显示id和函数名 我在网格中添加了一个行编辑插件,用于编辑函数设置。 问题是,当我尝试提交更改时,我在网格的左上角得到了一个小的红色三角形,控制台中没有任何错误代码。这些更改不会提交到MySQL数据库 我的程序工作和加载数据的方式: 这是我的功能商店: Ext.direct.Manager.addProvider(Ext.app.REM

亲爱的EXT爱好者们:

我正在做一个项目,我需要一个管理面板来编辑工作职能。 网格正在使用Ext.Direct与MySQL数据库通信。它可以很好地加载数据。 网格显示id和函数名

我在网格中添加了一个行编辑插件,用于编辑函数设置。 问题是,当我尝试提交更改时,我在网格的左上角得到了一个小的红色三角形,控制台中没有任何错误代码。这些更改不会提交到MySQL数据库

我的程序工作和加载数据的方式:

  • 这是我的功能商店:

    Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);  
    
    Ext.define("MCS.store.FunctionStore", 
    {
        extend: "Ext.data.Store",
        requires: "MCS.model.Functions",
        model: "MCS.model.Functions",
        id: "FunctionStore",
    
        proxy: 
        {
            type: "direct",
            api: 
            {
                read: QueryDatabase.getFunctions,
                create: QueryDatabase.createFunction,
                update: QueryDatabase.updateFunction,
                destroy: QueryDatabase.removeFunction,
            }
        },
    });
    
  • 在控制器中:呈现管理面板时,将使用以下函数加载存储:

    loadStore: function()
    {  
        functionStore.load();  
    }  
    
  • 这是显示函数的网格:

    var rowEditingFunctions = Ext.create("Ext.grid.plugin.RowEditing", 
    {  
        clicksToMoveEditor: 1,
        autoCancel: false,
        listeners: {
            edit: function(editor,e,opt)
            {
                var grid = e.grid;
                var record = e.record;
                console.log(record.data.functionName);
                var editedrecords = grid.getStore().getUpdatedRecords();
                console.log(editedrecords);
            }
        }
    });
    
    var functionGrid = Ext.create("Ext.grid.Panel", 
    {
        height: 500,
        width: 800,
        store: functionStore,
        title:"List of Job Functions - double click to edit",
        columns: [
        {
            dataIndex: "id",
            width: 50,
            text: "ID"
        },{
            dataIndex: "functionName",
            flex: 1,
            text: "Function",
            field: 
            {
                type: "textfield",
                allowBlank: false
            }
        }],
        plugins: [
            rowEditingFunctions
        ],
        dockedItems: [
        {
            xtype: "toolbar",
            store: functionStore,
            dock: "bottom",
            items: [
            {
                iconCls: "add",
                text: "Add",
                handler: function() 
                {
                    rowEditingFunctions.cancelEdit();
                    var newRecord = Ext.create("App.model.Functions");
                    functionStore.insert(0, newRecord);
                    rowEditingFunctions.startEdit(0, 0);
                    var sm = functionGrid.getSelectionModel();
                    functionGrid.on("edit", function() {
                        var record = sm.getSelection()
                        functionStore.sync();
                        functionStore.remove(record);
                        functionStore.load();
                    });
                }
            }, {
                iconCls: "delete",
                text: "Delete",
                handler: function() 
                {
                    rowEditingFunctions.cancelEdit();
                    var sm = functionGrid.getSelectionModel();
                    Ext.Msg.show(
                    {
                         title:"Delete Record?",
                         msg: "You are deleting a function permanently, this cannot be undone. Proceed?",
                         buttons: Ext.Msg.YESNO,
                         icon: Ext.Msg.QUESTION,
                         fn: function(btn)
                         {
                            if(btn === "yes") 
                            {
                                functionStore.remove(sm.getSelection());
                                functionStore.sync();
                            }
                         }
                    });
                }
            }]
        }]
    });
    
  • 正如您所看到的,我在RowEditing插件的编辑事件中添加了一个侦听器,这将在控制台中显示编辑记录的数组,就像它应该显示的那样。
    4.最后,这是更新数据库的PHP代码:

        public function updateFunction(stdClass $params)
        {
            $db = $this->__construct();
            if ($stmt = $db->prepare("UPDATE functions SET functionName=? WHERE id=?")) 
            {
                $stmt->bind_param('si', $functionName, $id);
                $functionName = $params->functionName;
                $id = (int) $params->id;
                $stmt->execute();
                $stmt->close();
            }
            return $this;
        }
    
    五,。奇怪的是:一旦我添加了一个作业函数,我就可以编辑所有其他函数,这些更改将提交到数据库中

    顺便说一句:我只是一个EXT的初学者,试图自己学习它,但在过去的几天里我一直在这个问题上伤脑筋,所以我决定问问你们


    提前感谢您的回答

    我把这个bug保留了几周,本周又开始研究它。 我找到了一个解决办法

    我已将以下代码添加到控制网格的控制器中:

    functionGrid.on('edit', function(editor, e) 
    {
        e.store.sync();
    });
    
    现在,当我更新一条记录时,小的红色三角形仍然会出现,但在e.store.sync()函数完成后,它会消失,数据库表也会更新

    不是100%清洁的解决方案,但它确实有效


    如果有人有更好的解决方案,请告诉我

    我遇到了类似的问题,这篇文章为我节省了很多时间。谢谢