jquery -jtable- listAction从javascript函数中获取对象。

时间:2023-01-27 23:35:32

Is it possible that listAction not call server function use AJAX , and the function will call to javascript function that return object ?

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

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

can help me?

可以帮助我吗?

2 个解决方案

#1


1  

thank i solve my proble, by edit jquery.jtable.js

感谢我通过编辑jquery.jtable.js来解决我的问题。

my script:

我的脚本:

function getObject(){
var result={};
result.Result="OK";
var array=[];
//...
{
array.push(new object...);
}
result.Records=array;
return result;
}

$('#ExecActDelays').jtable({
actions: {
listAction: getObject()
},

and in jquery.jtable.js i change

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);
                    }
                });
            }

to:(line 442)

(第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 complete my jquery.jtable.js

我完成我的jquery.jtable.js

#2


0  

Try do this

试着这样做

function foo(){
   return object;// JSON object
}

$('#ExecActDelays').jtable({
actions: {
listAction: foo()
},
///...

OR try this too

或者这也

var object = null;

function foo(){
   object = objectJSON;
}

$('#ExecActDelays').jtable({
actions: {
listAction: object
},
///...

#1


1  

thank i solve my proble, by edit jquery.jtable.js

感谢我通过编辑jquery.jtable.js来解决我的问题。

my script:

我的脚本:

function getObject(){
var result={};
result.Result="OK";
var array=[];
//...
{
array.push(new object...);
}
result.Records=array;
return result;
}

$('#ExecActDelays').jtable({
actions: {
listAction: getObject()
},

and in jquery.jtable.js i change

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);
                    }
                });
            }

to:(line 442)

(第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 complete my jquery.jtable.js

我完成我的jquery.jtable.js

#2


0  

Try do this

试着这样做

function foo(){
   return object;// JSON object
}

$('#ExecActDelays').jtable({
actions: {
listAction: foo()
},
///...

OR try this too

或者这也

var object = null;

function foo(){
   object = objectJSON;
}

$('#ExecActDelays').jtable({
actions: {
listAction: object
},
///...