Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
getAccessor
01/02/2010
15:24
Avatar
CTAPbIu_MABP
Ukrane, Lviv
Member
Members
Forum Posts: 10
Member Since:
26/01/2010
sp_UserOfflineSmall Offline

I noticed new function in github repository

        getAccessor = function(obj, expr) {
            var ret;
            ret = obj[expr];
            if(ret===undefined) {
                try {
                    ret = eval("obj."+expr);
                } catch (e) {}
            }
            return ret;
        },

it seems to be a misstype. there is no "obj" in global space to deal with so it might be

eval(obj+"."+expr);

And I think this is not very safe operation

eval("window"+"."+"alert(1)");

may be you should use this plugin

http://benalman.com/projects/j.....ct-plugin/

to get

eval(obj+"."+"a.b.c");
03/02/2010
20:14
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Thanks.

Did you try the script?

Also I know that using eval is not safe.

I will see if we can done it better. Thank you for the link - it help me to understand another way of doing this and maybe we will change this behaviour.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

04/02/2010
13:00
Avatar
CTAPbIu_MABP
Ukrane, Lviv
Member
Members
Forum Posts: 10
Member Since:
26/01/2010
sp_UserOfflineSmall Offline

>> Did you try the script?

Yes and I dont see any errors yet 🙂

08/02/2010
14:42
Avatar
CTAPbIu_MABP
Ukrane, Lviv
Member
Members
Forum Posts: 10
Member Since:
26/01/2010
sp_UserOfflineSmall Offline

Nice to see new code)))

08/02/2010
16:34
Avatar
CTAPbIu_MABP
Ukrane, Lviv
Member
Members
Forum Posts: 10
Member Since:
26/01/2010
sp_UserOfflineSmall Offline

I have a problem with this new code

Sorry but my inglish is too poor to describe this isue properly

I have a mapping

{name:"id", index:"id", width:40, sorttype:"string", editable:false},
{name:"login", index:"login", width:100, sorttype:"string", editable: true},
{name:"firstName", index:"firstName", width:100, sorttype:"string", editable:true},
{name:"lastName", index:"lastName", width:100, sorttype:"string", editable:true},
{name:"newPassword", index:"newPassword", hidden:true, editable: true, edittype:"password",editrules:{edithidden:true}},
{name:"confirmPassword",index:"confirmPassword", hidden:true, editable: true, edittype:"password",editrules:{edithidden:true}}

It not really matters what columns I have. Look at last two of them. They are hidden and editable. The front-end dont need real passwords becouse they are encrypted and so on. So I dont send this fields

row : [{ id : 1, cell : [1, "CTAPbIu_MABP", "First Name", "Last Name"]}]

before this changes (before you create getAccessor) this code works fine. and now it breaks with erroron line

if(prm.length)

becouse  obj[expr] === undefined  and prm is an integer and have no length

I dont think this is a bug but note that new code is incompatiable with old one

08/02/2010
17:09
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Thanks. Could you please try with this

        getAccessor = function(obj, expr) {
            var ret,p,prm;
            ret = obj[expr];
            if(ret===undefined) {
                if ( typeof expr === 'string' ) {
                    prm = expr.split('.');
                }

              try {
                if(prm.length) {
                    ret = obj;
                    while (ret && prm.length) {
                        p = prm.shift();
                        ret = ret[p];
                    }
                }

            } catch (e) {}
            }
            return ret;
        },

Please let me known if everthing is ok.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

08/02/2010
17:14
Avatar
CTAPbIu_MABP
Ukrane, Lviv
Member
Members
Forum Posts: 10
Member Since:
26/01/2010
sp_UserOfflineSmall Offline

try-catch successfully supress error 😉

31/05/2010
19:10
Avatar
zerikv
Member
Members
Forum Posts: 9
Member Since:
12/06/2009
sp_UserOfflineSmall Offline

Hello,

I have a problem with getAccessor() in grid.base.js v3.6.5 line 464

        getAccessor = function(obj, expr) {
            var ret,p,prm, i;
            if( typeof expr === 'function') { return expr(obj); }
            ret = obj[expr];
            if(ret===undefined) {
                if ( typeof expr === 'string' ) {
                    prm = expr.split('.');
                }
                try {
                    i = prm.length;
                    if( i ) {
                        ret = obj;
                        while (ret && i--) {
                            p = prm.shift();
                            ret = ret[p];
                        }
                    }
                } catch (e) {}
            }
            return ret;
        }

The line 464 is where variable "i" is affected with the length of variable "prm".

The variable "prm" is undefined when it's not a string.

To avoid this problem I have moved the try-catch bock inside the body of the   if ( typeof expr === 'string' ) {

Regards,

02/06/2010
20:14
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Thank you. This have sence. Fixed.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

02/09/2010
11:43
Avatar
tnorup
Copenhagen, Denmark
New Member
Members
Forum Posts: 1
Member Since:
02/09/2010
sp_UserOfflineSmall Offline

Sorry to say, but problems still remain.

I have experienced a web page to work perfectly on Ubuntu/Firefox 3.6.8 while the same page fails on Windows/Firefox 3.6.8.

The problem was that the expr parameter in some cases is an integer (i.e. neither string nor function) (don't ask me why - I haven't been able to figure that out; it only happen in a single grid out of 6 in my application). In that case, the local variable prm becomes undefined and an exception is raised.

I have fixed it by initialising prm to the empty string like this:

...

if (ret === undefined) {

      prm = ''

      if(typeof expr === 'string') {

...

However, this fix might bee too simplistic - possibly there should be an explicitly coded reaction on typeof expr === 'integer'.

The JSON data file causing the exception is this one, which - to me -seems flawless:

{"rows": [
{"cell": [26, "MS-S-728-0001                                                   ", "Kirsten", "2010-07-08", "TILL", "Finansministeriet", "Finansministeriet", null, "-"], "id": 26},
{"cell": [32, "MS-M-728-0001                                                   ", "PwSkrivDocTransmittal \u2013 edh", "2010-08-30", "S-ANS", "Finansministeriet", "Finansministeriet", 4, "Start"], "id": 32},
{"cell": [33, "MS-M-728-0003                                                   ", "PwSkrivDocTransmittal \u2013 edh", "2010-08-30", "TILL", "Kbh. Kommunes Milj\u00f8kontrol", "Finansministeriet", 4, "...0001"], "id": 33},
{"cell": [34, "MS-M-728-0004                                                   ", "placeholder 1 descr", "2010-08-30", "ANS", "Finansministeriet", "Finansministeriet", 4, "Start"], "id": 34},
{"cell": [35, "MS-M-728-0005                                                   ", "Placeholder 2", "2010-08-30", "-", "-", "-", 4, "-"], "id": 35}
], "total": 22, "page": 1, "pages": 3}

BTW, thanks for a brilliant plug-in!

Theodor

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
56 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information