• 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。加上后就不会报这样的错误了!

  • 相关阅读:
    [javaSE] 网络编程(浏览器客户端-自定义服务端)
    [javaSE] 网络编程(URLConnection)
    [javaSE] 网络编程(URL)
    [javaSE] IO流(FIle对象递归文件列表)
    tcping 与 telnet命令粗略使用
    让mysql监听ipv4
    shell脚本[] [[]] -n -z 的含义解析
    ansible的主机的默认配置部分
    MySQL备份与还原
    gunicorn 简介
  • 原文地址:https://www.cnblogs.com/xing----hao/p/3569407.html
Copyright © 2020-2023  润新知