EasyUI Forum
April 29, 2024, 01:30:51 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: TypeError: $.data(...) is undefined  (Read 8886 times)
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« on: October 21, 2019, 07:57:08 PM »

Whenever I call a function to open a dialog which has a datagrid, I got the following error in the console.

Code:
TypeError: $.data(...) is undefined

However this error does not cause any misbehaviour in my application. My code goes like this:

Code:
function openDialog(){
    $('body').desktop('openApp', {
         href:'datagridview.php',  
         //other code
    });
}

datagridview.php

Code:
<body>
    <table id="dg" data-options="href:view.php" class="easyui-datagrid">
         <th field="categoryName" halign="center" width="20" sortable="true" align="left">Category</th>
          //other codes follow
    </table>
</body>

I tested the code in Firefox, Chrome, Internet Explorer 11. I do not see any misbehavior. But since It is an error, I want to get rid of it. Please help.

Thanks
Alfred
« Last Edit: October 21, 2019, 08:39:35 PM by Alfred » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: October 23, 2019, 07:57:09 PM »

Your 'datagridview.php' should be:
Code:
<table id="dg" data-options="fit:true" class="easyui-datagrid">
<thead>
<tr>
<th field="categoryName" halign="center" width="200" sortable="true" align="left">Category</th>
<th field="categoryName2" halign="center" width="200" sortable="true" align="left">Category2</th>
</tr>
</thead>
</table>

No error occurs on the console.
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #2 on: October 27, 2019, 09:44:29 PM »

Thanks for the reply.

the datagridview.php contains a a datagrid definion. It has a different url for getting the datagrid json. So the complete code looks like below:

This code is in index.php:

Code:
function openDialog(){
    $('body').desktop('openApp', {
         href:'datagridview.php',  
         //other code
    });
}

We have another file datagridview.php, which has the following datagrid code:

Code:
<table id="dg" data-options="url:view.php" class="easyui-datagrid">
         <th field="categoryName" halign="center" width="20" sortable="true" align="left">Category</th>
          //other codes follow
</table>

So when we run
Code:
openDiaglog()
function, It opens a new dialog. Inside the dialog, we have a datagrid that will load json from view.php. So the error still exists. The complete console error is:

TypeError: $.data(...) is undefined easyui.min.js:1:245666
    getPager http://test.com/js/easyui.min.js:1
    datagrid http://test.com/js/easyui.min.js:1
    loaded http://test.com/js/easyui.min.js:1
    jQuery 2
    loaded http://test.com/js/easyui.min.js:1
    datagrid http://test.com/js/easyui.min.js:1
    _78f http://test.com/js/easyui.min.js:1
    success http://test.com/js/easyui.min.js:6
    jQuery 4


I hope you can fix the error.

Thanks and regards,
Alfred



« Last Edit: October 27, 2019, 09:48:15 PM by Alfred » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: October 28, 2019, 02:33:58 AM »

Please look at this example https://www.jeasyui.com/demo/test/test8.html. It works fine.

test8_1.php
Code:
<table id="dg" data-options="fit:true,url:'test8_2.php'" class="easyui-datagrid">
<thead>
<tr>
<th field="categoryName" halign="center" width="200" sortable="true" align="left">Category</th>
<th field="categoryName2" halign="center" width="200" sortable="true" align="left">Category2</th>
</tr>
</thead>
</table>

test8_2.php
Code:
<?php

$data 
= array(
array('categoryName'=>'categoryName11','categoryName2'=>'categoryName12'),
array('categoryName'=>'categoryName21','categoryName2'=>'categoryName22'),
array('categoryName'=>'categoryName31','categoryName2'=>'categoryName32'),
);

echo 
json_encode($data);
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #4 on: October 28, 2019, 07:52:35 PM »

Thanks for the reply.

Your example just works fine, yet the error still exists in my attempted code. It may be due to the way the pagination works. In your example the pagination is not included. I am using jquery 1.12.4. and easyui 1.7.x.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!