未捕获的TypeError:对象app.data.proxy.CustomSql没有方法'apply'sencha touch

时间:2013-11-03 11:40:45

标签: sqlite proxy sencha-touch override

嗨Stackoverflow人!

我在sencha touch框架中编码,我已经定义了对Ext.data.proxy.Sql的覆盖......

当app加载时,显示下一个错误:

Uncaught TypeError: Object App.data.proxy.CustomSql has no method 'apply' ...

覆盖是:

Ext.define('app.data.proxy.CustomSql', {    
    override: 'Ext.data.proxy.Sql',
    isSQLProxy: false, 
    setSql: function(sql) {
        this.customSql = sql;
        console.log('definiendo');
    },
    getSql: function() {
        return(this.customSql);
    },
    selectRecords: function(transaction, params, callback, scope) {
        console.log('seles');
        var me = this,
        table = me.getTable(),
        idProperty = me.getModel().getIdProperty(),
        sql = 'SELECT * FROM ' + table,
        records = [],
        filterStatement = ' WHERE ',
        sortStatement = ' ORDER BY ',
        i, ln, data, result, count, rows, filter, sorter, property, value;


        result = new Ext.data.ResultSet({
        records: records,
        success: true
    });


    if (!Ext.isObject(params)) {
        sql += filterStatement + idProperty + ' = ' + params;
    } else {
        ln = params.filters && params.filters.length;
        if (ln) {
            for (i = 0; i < ln; i++) {
                filter = params.filters[i];
                property = filter.getProperty();
                value = filter.getValue();
                if (property !== null) {
                    sql += filterStatement + property + ' ' + (filter.getAnyMatch() ? ('LIKE \'%' + value + '%\'') : ('= \'' + value + '\''));
                    filterStatement = ' AND ';
                }
            }
        }


        ln = params.sorters && params.sorters.length;
        if (ln) {
            for (i = 0; i < ln; i++) {
                sorter = params.sorters[i];
                property = sorter.getProperty();
                if (property !== null) {
                    sql += sortStatement + property + ' ' + sorter.getDirection();
                    sortStatement = ', ';
                }
            }
        }


        // handle start, limit, sort, filter and group params
        if (params.page !== undefined) {
            sql += ' LIMIT ' + parseInt(params.start, 10) + ', ' + parseInt(params.limit, 10);
        }
    }


    console.log(this.customSql);        
    if (this.customSql) {
        sql = this.customSql;
        delete this.customSql; 
    }


    transaction.executeSql(sql, null,
        function(transaction, resultSet) {
            rows = resultSet.rows;
            count = rows.length;


            for (i = 0, ln = count; i < ln; i++) {
                data = rows.item(i);
                records.push({
                    clientId: null,
                    id: data[idProperty],
                    data: data,
                    node: data
                });
            }


            result.setSuccess(true);
            result.setTotal(count);
            result.setCount(count);


            if (typeof callback == 'function') {
                callback.call(scope || me, result);
            }
        },
        function(transaction, errors) {
            result.setSuccess(false);
            result.setTotal(0);
            result.setCount(0);


            if (typeof callback == 'function') {
                callback.call(scope || me, result);
            }
        }
    );
},

});

有什么想法吗? 欢迎任何帮助。

提前致谢。 ;)

1 个答案:

答案 0 :(得分:1)

浏览您的代码:

    selectRecords()函数中的
  1. 您有很多,而不是;

    selectRecords: function(transaction, params, callback, scope) {
        console.log('seles');
        var me = this,
        table = me.getTable(),
    ...
    

    您正在混合;,
    这是功能,您应该始终将 ; 放在行尾。

    正如 @StephenTremaine 指出的那样(不确定我是如何忽略这一点)上面不是一个问题,因为人们可以简单地使用逗号来生成声明列表。

  2. 在最后一个Ext.define右括号 ,

    之前,您有一个 });
        },
    });
    

    这是错误的。

  3. 试图清理并修复您的代码:

    Ext.define('app.data.proxy.CustomSql', {
        override: 'Ext.data.proxy.Sql',
        isSQLProxy: false, 
        setSql: function(sql) {
            this.customSql = sql;
            console.log('definiendo');
        },
        getSql: function() {
            return(this.customSql);
        },
        selectRecords: function(transaction, params, callback, scope) {
            console.log('seles');
            var me = this;
            table = me.getTable();
            idProperty = me.getModel().getIdProperty();
            sql = 'SELECT * FROM ' + table;
            records = [];
            filterStatement = ' WHERE ';
            sortStatement = ' ORDER BY ';
            i, ln, data, result, count, rows, filter, sorter, property, value;
    
    
            result = new Ext.data.ResultSet({
                records: records,
                success: true
            });
    
    
            if (!Ext.isObject(params)) {
                sql += filterStatement + idProperty + ' = ' + params;
            } else {
                ln = params.filters && params.filters.length;
                if (ln) {
                    for (i = 0; i < ln; i++) {
                        filter = params.filters[i];
                        property = filter.getProperty();
                        value = filter.getValue();
                        if (property !== null) {
                            sql += filterStatement + property + ' ' + (filter.getAnyMatch() ? ('LIKE \'%' + value + '%\'') : ('= \'' + value + '\''));
                            filterStatement = ' AND ';
                        }
                    }
                }
    
                ln = params.sorters && params.sorters.length;
                if (ln) {
                    for (i = 0; i < ln; i++) {
                        sorter = params.sorters[i];
                        property = sorter.getProperty();
                        if (property !== null) {
                            sql += sortStatement + property + ' ' + sorter.getDirection();
                            sortStatement = ', ';
                        }
                    }
                }
    
                // handle start, limit, sort, filter and group params
                if (params.page !== undefined) {
                    sql += ' LIMIT ' + parseInt(params.start, 10) + ', ' + parseInt(params.limit, 10);
                }
            }
    
    
            console.log(this.customSql);
            if (this.customSql) {
                sql = this.customSql;
                delete this.customSql; 
            }
    
    
            transaction.executeSql(sql, null,
                function(transaction, resultSet) {
                    rows = resultSet.rows;
                    count = rows.length;
    
    
                    for (i = 0, ln = count; i < ln; i++) {
                        data = rows.item(i);
                        records.push({
                            clientId: null,
                            id: data[idProperty],
                            data: data,
                            node: data
                        });
                    }
    
                    result.setSuccess(true);
                    result.setTotal(count);
                    result.setCount(count);
    
                    if (typeof callback == 'function') {
                        callback.call(scope || me, result);
                    }
                },
    
                function(transaction, errors) {
                    result.setSuccess(false);
                    result.setTotal(0);
                    result.setCount(0);
    
                    if (typeof callback == 'function') {
                        callback.call(scope || me, result);
                    }
                }
            );
        }
    });