zoukankan      html  css  js  c++  java
  • extjs Cannot read property 'dom' of null

    如果你的EXTJS报错: Cannot read property 'dom' of null,那就有可能是因为你的HTML或者JSP文件中的BODY标签里面少了个东西比如代码是:

    1. <html>  
    2. <head>  
    3.     <title>Hello Ext</title>  
    4.       <meta http-equiv="content-type" content="text/html; charset=UTF-8">  
    5.     <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">    
    6.     <script type="text/javascript" src="extjs/ext-all.js"></script>    
    7.       
    8. </head>  
    9. <body >  
    10.   <div id="example-grid"></div>  
    11. </body>  
    12. </html>  
    13.  <script type="text/javascript">  
    14. Ext.require([  
    15.     'Ext.data.*',  
    16.     'Ext.grid.*'  
    17. ]);  
    18.   
    19. Ext.onReady(function(){  
    20.     Ext.define('Book',{  
    21.         extend: 'Ext.data.Model',  
    22.         proxy: {  
    23.             type: 'ajax',  
    24.             reader: 'xml'  
    25.         },  
    26.         fields: [  
    27.             // set up the fields mapping into the xml doc  
    28.             // The first needs mapping, the others are very basic  
    29.             {name: 'Author', mapping: '@author.name'},  
    30.             'Title', 'Manufacturer', 'ProductGroup'  
    31.         ]  
    32.     });  
    33.   
    34.     // create the Data Store  
    35.     var store = Ext.create('Ext.data.Store', {  
    36.         model: 'Book',  
    37.         autoLoad: true,  
    38.         proxy: {  
    39.             // load using HTTP  
    40.             type: 'ajax',  
    41.             url: 'sampledata-sheldon.xml',  
    42.             // the return will be XML, so lets set up a reader  
    43.             reader: {  
    44.                 type: 'xml',  
    45.                 // records will have an "Item" tag  
    46.                 record: 'Item',  
    47.                 idProperty: 'ASIN',  
    48.                 totalRecords: '@total'  
    49.             }  
    50.         }  
    51.     });  
    52.   
    53.     // create the grid  
    54.     Ext.create('Ext.grid.Panel', {  
    55.         store: store,  
    56.         columns: [  
    57.             {text: "Author", flex: 1, dataIndex: 'Author'},  
    58.             {text: "Title",  180, dataIndex: 'Title'},  
    59.             {text: "Manufacturer",  115, dataIndex: 'Manufacturer'},  
    60.             {text: "Product Group",  100, dataIndex: 'ProductGroup'}  
    61.         ],  
    62.         renderTo:'example-grid',  
    63.          540,  
    64.         height: 200  
    65.     });  
    66. });  
    67. </script>  

    如果这个代码里面没有id为'example-grid'的DIV的话会报错:Cannot read property 'dom' of null。加上后就不会报这样的错误了!

  • 相关阅读:
    字符串hash
    堆优化的最短路
    unordered_map 的火车头
    扩展欧几里得求ax+by=c的最小正整数解
    欧拉筛
    Codeforces Round 649 (Rated for Div. 2)D. Ehab s Last Corollary (图论+简单环)
    牛客SQL题解-找出所有员工具体的薪水salary情况
    牛客SQL题解-查找薪水变动超过15次的员工号emp_no以及其对应的变动次数t
    牛客SQL题解-查找所有已经分配部门的员工的last_name和first_name以及dept_no,也包括暂时没有分配具体部门的员工
    牛客SQL题解- 查找所有已经分配部门的员工的last_name和first_name
  • 原文地址:https://www.cnblogs.com/xing----hao/p/3569407.html
Copyright © 2011-2022 走看看