删除路径未找到,存储代理错误?

时间:2013-06-04 11:35:37

标签: javascript extjs

我是extjs的新手,我正面临一个问题,我真的不明白为什么它不起作用。我正在尝试从我的网格和填充网格的数据库中删除一行,但我的客户说我的服务器上没有删除(抱歉英文不好)

这是我的代码:

店: 的

Ext.define('LU.store.Audios', {
    extend: 'Ext.data.Store',       
        autoLoad: true,
        autoSync: true,
        model: 'LU.model.Audio',

        proxy: {
            type: 'rest',

            api: {
                create: 'http://localhost:3000/upload',
                read: 'http://localhost:3000/list',
                update: 'http://localhost:3000/update',
                destroy: 'http://localhost:3000/delete'
            },

            reader: {
                type: 'json',
                root: 'audios',
                totalProperty  : 'total',
                successProperty: 'success'
            },
            writer: {
                type: 'json'
            }       

        }


    });

模特:

Ext.define('LU.model.Audio', {
    extend: 'Ext.data.Model',
    fields: [ 
        { name: 'id', type: 'int'},
        { name: 'name', type: 'string'},
        { name: 'path', type: 'string'}
    ],

});

观点:

Ext.define('LU.view.Main', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.mainview',
    id: 'main',





    initComponent: function() {

        this.items = [{

        }, {
            xtype: 'grid',
            title: 'Audio liste',
            store: 'Audios',
            id: 'mygrid',

            columns: [
                {text: 'Dateiname', dataIndex: 'name'},
                {text: 'Dateipfad', dataIndex: 'path'}
            ],
            listeners : {
                afterrender : function (grid) {
                        grid.addDocked({
                            xtype: 'toolbar',
                            dock: 'top',
                            items: [{
                                text: 'Delete',
                                action: 'delete'
                            }, {
                                text: 'Download'
                            }]
                        });
                    }

            },

        }
        ];
        this.callParent(arguments);
    }
});

和控制器:

Ext.define('LU.controller.MainController', {
    extend: 'Ext.app.Controller',

    views:  ['Main'],
    stores: ['Audios'],
    models: ['Audio'],

    init: function() {
        this.control({

        'mainview button[action=delete]': {
                click: this.delete
        }


        });

    },

    delete: function () {
        var grid = Ext.getCmp('mygrid');
        var row = grid.getSelectionModel().getSelection();

        Ext.getStore("Audios").remove(row);


    },



});

和服务器:

var express = require ('express');
var app = express();
var fs = require('fs');
var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : 'root',
});



connection.connect();
connection.query('USE diktierserver');

app.use(express.bodyParser()); 


app.all('*', function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, Origin, Accept');
    res.header('Access-Control-Allow-Credentials', 'true');
    if(req.method.toLowerCase()==='options'){
        res.send(200);
    }else{
        next();
    }
});
app.delete('/delete', function (req,res) {

    res.header('Access-Control-Allow-Origin', '*');
    res.header('Content-Type','text/plain; charset=UTF8');

        console.log(req);
        var id = req.params.id;

        connection.query('DELETE FROM audio WHERE id = ' + id +'', function (err,result) {
        if (err) throw err;
        console.log(name + 'deleted');
        res.status(200).send(JSON.stringify());
    });

});
app.listen(3000);

1 个答案:

答案 0 :(得分:0)

使用Ext.data.proxy.Rest时,删除/删除操作的默认actionMethod是HTTP DELETE谓词。因此,您应确保您的Web服务器设置允许此HTTP谓词。我遇到过一些问题,其中一些负载均衡器甚至没有实现DELETE动词,因此无法利用Rest代理中的默认操作。

当然,您可以更改通过DELETE操作发送的VERB。例如,您可以将其更改为PUT,并且仍然可以获得与DELETE相同的indempotent行为。