【问题标题】:jquery -jtable- listAction get object from javascript functionjquery -jtable- listAction 从 javascript 函数中获取对象
【发布时间】:2014-01-07 09:05:31
【问题描述】:

listAction 是否有可能不调用服务器函数使用 AJAX,并且该函数将调用返回对象的 javascript 函数?

$('#ExecActDelays').jtable({
actions: {
listAction://get object from javascript no call server method
},
///...

可以帮助我吗?

【问题讨论】:

    标签: html jquery-ui jquery jquery-jtable


    【解决方案1】:

    谢谢 我解决了我的问题,通过编辑jquery.jtable.js

    我的脚本:

    function getObject(){
    var result={};
    result.Result="OK";
    var array=[];
    //...
    {
    array.push(new object...);
    }
    result.Records=array;
    return result;
    }
    
    $('#ExecActDelays').jtable({
    actions: {
    listAction: getObject()
    },
    

    在 jquery.jtable.js 我改变了

     self._ajax({
                        url: loadUrl,
                        data: self._lastPostData,
                        success: function (data) {
                            self._hideBusy();
    
                            //Show the error message if server returns error
                            if (data.Result != 'OK') {
                                self._showError(data.Message);
                                return;
                            }
    
                            //Re-generate table rows
                            self._removeAllRows('reloading');
                            self._addRecordsToTable(data.Records);
    
                            self._onRecordsLoaded(data);
    
                            //Call complete callback
                            if (completeCallback) {
                                completeCallback();
                            }
                        },
                        error: function () {
                            self._hideBusy();
                            self._showError(self.options.messages.serverCommunicationError);
                        }
                    });
                }
    

    到:(第 442 行)

     if (typeof loadUrl == "string") {
                    self._ajax({
                        url: loadUrl,
                    data: self._lastPostData,
                    success: function (data) {
                        self._hideBusy();
    
                        //Show the error message if server returns error
                        if (data.Result != 'OK') {
                            self._showError(data.Message);
                            return;
                        }
    
                        //Re-generate table rows
                        self._removeAllRows('reloading');
                        self._addRecordsToTable(data.Records);
    
                        self._onRecordsLoaded(data);
    
                        //Call complete callback
                        if (completeCallback) {
                            completeCallback();
                        }
                    },
                    error: function () {
                        self._hideBusy();
                        self._showError(self.options.messages.serverCommunicationError);
                    }
                });
            }
            else {//no from server method
                self._hideBusy();
    
                //Re-generate table rows
                self._removeAllRows('reloading');
                self._addRecordsToTable(loadUrl.Records);
    
                self._onRecordsLoaded(loadUrl);
    
                //Call complete callback
                if (completeCallback) {
                    completeCallback();
                }
            }
    

    我的完整 my jquery.jtable.js

    【讨论】:

    • 基于documentation可以使用url或者函数,不知道1月份是否已经生效
    【解决方案2】:

    试试这个

    function foo(){
       return object;// JSON object
    }
    
    $('#ExecActDelays').jtable({
    actions: {
    listAction: foo()
    },
    ///...
    

    或者也试试这个

    var object = null;
    
    function foo(){
       object = objectJSON;
    }
    
    $('#ExecActDelays').jtable({
    actions: {
    listAction: object
    },
    ///...
    

    【讨论】:

    • 我已经试过了它不起作用它是指函数返回的URL地址以从服务器获取记录列表你试试吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多