在4.0.7版之前的版本都可通过select方法进行处理,但是4.1之后就不行了。经研究,问题出现在渲染过程上。下面通过一个例子测试一下。

测试示例代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css")" />
  7. <script type="text/javascript" src="extjs/bootstrap.js")"></script>
  8. </head>
  9. <body>
  10. <script>
  11. Ext.onReady(function() {
  12. if(Ext.BLANK_IMAGE_URL.substr(0,4)!="data"){
  13. Ext.BLANK_IMAGE_URL="./images/s.gif";
  14. }
  15. Ext.create("Ext.data.TreeStore",{
  16. proxy: {
  17. type: 'ajax',
  18. url:"tree.js"
  19. },
  20. storeId:"TestStore"
  21. });
  22. Ext.widget("treepanel",{
  23. title: "Tree Test", rootVisible: false, store: "TestStore",
  24. renderTo:Ext.getBody(),
  25. width:400,height:600,
  26. viewConfig:{
  27. listeners:{
  28. refresh:function(view){
  29. view.getSelectionModel().select(0);
  30. }
  31. }
  32. }
  33. });
  34. });
  35. </script>
  36. </body>
  37. </html>

加载的树节点代码(tree.js):

  1. [
  2. {
  3. "id": "all",
  4. "text": "All",
  5. "leaf": true
  6. },
  7. {
  8. "id": "ALFKI",
  9. "text": "Alfreds Futterkiste",
  10. "leaf": true
  11. },
  12. {
  13. "id": "ANATR",
  14. "text": "Ana Trujillo Emparedados y helados",
  15. "leaf": true
  16. },
  17. {
  18. "id": "ANTON",
  19. "text": "Antonio Moreno Taquería",
  20. "leaf": true
  21. },
  22. {
  23. "id": "AROUT",
  24. "text": "Around the Horn",
  25. "leaf": true
  26. },
  27. {
  28. "id": "BERGS",
  29. "text": "Berglunds snabbk?p",
  30. "leaf": true
  31. },
  32. {
  33. "id": "BLAUS",
  34. "text": "Blauer See Delikatessen",
  35. "leaf": true
  36. },
  37. {
  38. "id": "BLONP",
  39. "text": "Blondesddsl père et fils",
  40. "leaf": true
  41. },
  42. {
  43. "id": "BOLID",
  44. "text": "Bólido Comidas preparadas",
  45. "leaf": true
  46. },
  47. {
  48. "id": "BONAP",
  49. "text": "Bon app'",
  50. "leaf": true
  51. },
  52. {
  53. "id": "BOTTM",
  54. "text": "Bottom-Dollar Markets",
  55. "leaf": true
  56. },
  57. {
  58. "id": "BSBEV",
  59. "text": "B's Beverages",
  60. "leaf": true
  61. },
  62. {
  63. "id": "CACTU",
  64. "text": "Cactus Comidas para llevar",
  65. "leaf": true
  66. },
  67. {
  68. "id": "CENTC",
  69. "text": "Centro comercial Moctezuma",
  70. "leaf": true
  71. },
  72. {
  73. "id": "CHOPS",
  74. "text": "Chop-suey Chinese",
  75. "leaf": true
  76. },
  77. {
  78. "id": "COMMI",
  79. "text": "Comércio Mineiro",
  80. "leaf": true
  81. },
  82. {
  83. "id": "CONSH",
  84. "text": "Consolidated Holdings",
  85. "leaf": true
  86. },
  87. {
  88. "id": "WANDK",
  89. "text": "Die Wandernde Kuh",
  90. "leaf": true
  91. },
  92. {
  93. "id": "DRACD",
  94. "text": "Drachenblut Delikatessen",
  95. "leaf": true
  96. },
  97. {
  98. "id": "DUMON",
  99. "text": "Du monde entier",
  100. "leaf": true
  101. },
  102. {
  103. "id": "EASTC",
  104. "text": "Eastern Connection",
  105. "leaf": true
  106. },
  107. {
  108. "id": "ERNSH",
  109. "text": "Ernst Handel",
  110. "leaf": true
  111. },
  112. {
  113. "id": "FAMIA",
  114. "text": "Familia Arquibaldo",
  115. "leaf": true
  116. },
  117. {
  118. "id": "FISSA",
  119. "text": "FISSA Fabrica Inter. Salchichas S.A.",
  120. "leaf": true
  121. },
  122. {
  123. "id": "FOLIG",
  124. "text": "Folies gourmandes",
  125. "leaf": true
  126. },
  127. {
  128. "id": "FOLKO",
  129. "text": "Folk och f? HB",
  130. "leaf": true
  131. },
  132. {
  133. "id": "FRANR",
  134. "text": "France restauration",
  135. "leaf": true
  136. },
  137. {
  138. "id": "FRANS",
  139. "text": "Franchi S.p.A.",
  140. "leaf": true
  141. },
  142. {
  143. "id": "FRANK",
  144. "text": "Frankenversand",
  145. "leaf": true
  146. },
  147. {
  148. "id": "FURIB",
  149. "text": "Furia Bacalhau e Frutos do Mar",
  150. "leaf": true
  151. },
  152. {
  153. "id": "GALED",
  154. "text": "Galería del gastrónomo",
  155. "leaf": true
  156. },
  157. {
  158. "id": "GODOS",
  159. "text": "Godos Cocina Típica",
  160. "leaf": true
  161. },
  162. {
  163. "id": "GOURL",
  164. "text": "Gourmet Lanchonetes",
  165. "leaf": true
  166. },
  167. {
  168. "id": "GREAL",
  169. "text": "Great Lakes Food Market",
  170. "leaf": true
  171. },
  172. {
  173. "id": "GROSR",
  174. "text": "GROSELLA-Restaurante",
  175. "leaf": true
  176. },
  177. {
  178. "id": "HANAR",
  179. "text": "Hanari Carnes",
  180. "leaf": true
  181. },
  182. {
  183. "id": "HILAA",
  184. "text": "HILARION-Abastos",
  185. "leaf": true
  186. },
  187. {
  188. "id": "HUNGC",
  189. "text": "Hungry Coyote Import Store",
  190. "leaf": true
  191. },
  192. {
  193. "id": "HUNGO",
  194. "text": "Hungry Owl All-Night Grocers",
  195. "leaf": true
  196. },
  197. {
  198. "id": "ISLAT",
  199. "text": "Island Trading",
  200. "leaf": true
  201. },
  202. {
  203. "id": "KOENE",
  204. "text": "K?niglich Essen",
  205. "leaf": true
  206. },
  207. {
  208. "id": "LACOR",
  209. "text": "La corne d'abondance",
  210. "leaf": true
  211. },
  212. {
  213. "id": "LAMAI",
  214. "text": "La maison d'Asie",
  215. "leaf": true
  216. },
  217. {
  218. "id": "LAUGB",
  219. "text": "Laughing Bacchus Wine Cellars",
  220. "leaf": true
  221. },
  222. {
  223. "id": "LAZYK",
  224. "text": "Lazy K Kountry Store",
  225. "leaf": true
  226. },
  227. {
  228. "id": "LEHMS",
  229. "text": "Lehmanns Marktstand",
  230. "leaf": true
  231. },
  232. {
  233. "id": "LETSS",
  234. "text": "Let's Stop N Shop",
  235. "leaf": true
  236. },
  237. {
  238. "id": "LILAS",
  239. "text": "LILA-Supermercado",
  240. "leaf": true
  241. },
  242. {
  243. "id": "LINOD",
  244. "text": "LINO-Delicateses",
  245. "leaf": true
  246. },
  247. {
  248. "id": "LONEP",
  249. "text": "Lonesome Pine Restaurant",
  250. "leaf": true
  251. },
  252. {
  253. "id": "MAGAA",
  254. "text": "Magazzini Alimentari Riuniti",
  255. "leaf": true
  256. },
  257. {
  258. "id": "MAISD",
  259. "text": "Maison Dewey",
  260. "leaf": true
  261. },
  262. {
  263. "id": "MEREP",
  264. "text": "Mère Paillarde",
  265. "leaf": true
  266. },
  267. {
  268. "id": "MORGK",
  269. "text": "Morgenstern Gesundkost",
  270. "leaf": true
  271. },
  272. {
  273. "id": "NORTS",
  274. "text": "North/South",
  275. "leaf": true
  276. },
  277. {
  278. "id": "OCEAN",
  279. "text": "Océano Atlántico Ltda.",
  280. "leaf": true
  281. },
  282. {
  283. "id": "OLDWO",
  284. "text": "Old World Delicatessen",
  285. "leaf": true
  286. },
  287. {
  288. "id": "OTTIK",
  289. "text": "Ottilies K?seladen",
  290. "leaf": true
  291. },
  292. {
  293. "id": "PARIS",
  294. "text": "Paris spécialités",
  295. "leaf": true
  296. },
  297. {
  298. "id": "PERIC",
  299. "text": "Pericles Comidas clásicas",
  300. "leaf": true
  301. },
  302. {
  303. "id": "PICCO",
  304. "text": "Piccolo und mehr",
  305. "leaf": true
  306. },
  307. {
  308. "id": "PRINI",
  309. "text": "Princesa Isabel Vinhos",
  310. "leaf": true
  311. },
  312. {
  313. "id": "QUEDE",
  314. "text": "Que Delícia",
  315. "leaf": true
  316. },
  317. {
  318. "id": "QUEEN",
  319. "text": "Queen Cozinha",
  320. "leaf": true
  321. },
  322. {
  323. "id": "QUICK",
  324. "text": "QUICK-Stop",
  325. "leaf": true
  326. },
  327. {
  328. "id": "RANCH",
  329. "text": "Rancho grande",
  330. "leaf": true
  331. },
  332. {
  333. "id": "RATTC",
  334. "text": "Rattlesnake Canyon Grocery",
  335. "leaf": true
  336. },
  337. {
  338. "id": "REGGC",
  339. "text": "Reggiani Caseifici",
  340. "leaf": true
  341. },
  342. {
  343. "id": "RICAR",
  344. "text": "Ricardo Adocicados",
  345. "leaf": true
  346. },
  347. {
  348. "id": "RICSU",
  349. "text": "Richter Supermarkt",
  350. "leaf": true
  351. },
  352. {
  353. "id": "ROMEY",
  354. "text": "Romero y tomillo",
  355. "leaf": true
  356. },
  357. {
  358. "id": "SANTG",
  359. "text": "Santé Gourmet",
  360. "leaf": true
  361. },
  362. {
  363. "id": "SAVEA",
  364. "text": "Save-a-lot Markets",
  365. "leaf": true
  366. },
  367. {
  368. "id": "SEVES",
  369. "text": "Seven Seas Imports",
  370. "leaf": true
  371. },
  372. {
  373. "id": "SIMOB",
  374. "text": "Simons bistro",
  375. "leaf": true
  376. },
  377. {
  378. "id": "SPECD",
  379. "text": "Spécialités du monde",
  380. "leaf": true
  381. },
  382. {
  383. "id": "SPLIR",
  384. "text": "Split Rail Beer & Ale",
  385. "leaf": true
  386. },
  387. {
  388. "id": "SUPRD",
  389. "text": "Suprêmes délices",
  390. "leaf": true
  391. },
  392. {
  393. "id": "THEBI",
  394. "text": "The Big Cheese",
  395. "leaf": true
  396. },
  397. {
  398. "id": "THECR",
  399. "text": "The Cracker Box",
  400. "leaf": true
  401. },
  402. {
  403. "id": "TOMSP",
  404. "text": "Toms Spezialit?ten",
  405. "leaf": true
  406. },
  407. {
  408. "id": "TORTU",
  409. "text": "Tortuga Restaurante",
  410. "leaf": true
  411. },
  412. {
  413. "id": "TRADH",
  414. "text": "Tradi??o Hipermercados",
  415. "leaf": true
  416. },
  417. {
  418. "id": "TRAIH",
  419. "text": "Trail's Head Gourmet Provisioners",
  420. "leaf": true
  421. },
  422. {
  423. "id": "VAFFE",
  424. "text": "Vaffeljernet",
  425. "leaf": true
  426. },
  427. {
  428. "id": "VICTE",
  429. "text": "Victuailles en stock",
  430. "leaf": true
  431. },
  432. {
  433. "id": "VINET",
  434. "text": "Vins et alcools Chevalier",
  435. "leaf": true
  436. },
  437. {
  438. "id": "WARTH",
  439. "text": "Wartian Herkku",
  440. "leaf": true
  441. },
  442. {
  443. "id": "WELLI",
  444. "text": "Wellington Importadora",
  445. "leaf": true
  446. },
  447. {
  448. "id": "WHITC",
  449. "text": "White Clover Markets",
  450. "leaf": true
  451. },
  452. {
  453. "id": "WILMK",
  454. "text": "Wilman Kala",
  455. "leaf": true
  456. },
  457. {
  458. "id": "WOLZA",
  459. "text": "Wolski  Zajazd",
  460. "leaf": true
  461. }
  462. ]

如果按以前习惯,使用“view.getSelectionModel().select(0);”,Firebug会提示以下错误:

  1. o is undefined
  2. return o.id;   ext-all-debug.js (第 43468 行)

将“view.getSelectionModel().select(0);”修改为“console.log(view)”,Firebug提示以下:

  1. [试用版] Ext.tree.View [0] { id="treeview-1012"}  tree.html (第 32 行)
  2. [试用版] Ext.tree.View [1] { id="treeview-1012"}  tree.html (第 32 行)

这里居然触发了两次refresh事件,问题就出现在第一次的触发上,修改代码为:

  1. console.log(view.node.firstChild)

Firebug提示:

  1. null
  2. tree.html (第 33 行)
  3. [试用版] Ext.data.Store.ImplicitModel-TestStore { id="Ext.data.Store.ImplicitModel-TestStore-all", internalId="all"}
  4. tree.html (第 33 行)

从这里就很明显看到了,第一触发refresh事件时,根节点的第一个节点为null,执行select方法肯定找不到选择节点。因而要正确进行选择,就必须判断firstChild是否存在,如果存在,才进行选择。因而,将代码修改为如下代码即可正确选择第一行了:

  1. var node=view.node.firstChild;
  2. if(node){
  3. view.getSelectionModel().select(node);
  4. }

解决Ext JS 4.1版本Tree在刷新时选择第一行的问题相关推荐

  1. [Ext JS] 3.3 树(Tree)的定义和使用

    树的构成 树面板:Ext.tree.Panel , 面板用来创建一个树的组件 树视图:Ext.tree.View , 对树的样式做一些配置 ,比如是否显示根节点(rootVisible), 视图不直接 ...

  2. Python读取Excel文件时缺少第一行的解决办法

    python在读取Excel文件时默认会把第一行当做列名,所以导致会缺少一行.解决办法如下: 加入header=None

  3. Ext.js Tree

    今天学习Ext.js 4.2版本的Tree组件,发现一个问题,就是model里面不能写类型,要不然就不发送请求,而且text是必须的字段,区分大小写. 转载于:https://www.cnblogs. ...

  4. 【翻译】Ext JS 6早期访问版本发布

    早期访问版本是什么 如何参与 都包括什么 Sencha Ext JS 6 Sencha Pivot Grid Sencha Cmd 6 JetBrains IDE插件 反馈 原文:Announcing ...

  5. Ext JS 4倒计时:开发者预览版

    作为Ext JS团队的代表,我很高兴地宣布第一个Ext JS 4开发者预览版 发布了.Ext JS 4是到目前为止,我们所做的改动最大,有史以来最先进的Javascript框架.从生成HTML代码到类 ...

  6. Ext JS 4倒计时:动态加载和新的类系统

    Today we're excited to release the first in a series of brand new features in Ext JS 4. Over the nex ...

  7. 【翻译】Ext JS最新技巧——2015-8-11

    原文:Top Support Tips Seth Lemmons:使用棒极了的Awesome Font Ext JS 6附带了一个新的海卫一主题,可以使用Font Awesome字体作为背景图像的图标 ...

  8. ext get id js_【翻译】Ext JS最新技巧——2015-8-11

    Seth Lemmons:使用棒极了的Awesome Font Ext JS 6附带了一个新的海卫一主题,可以使用Font Awesome字体作为背景图像的图标.不过,你知道如何通过"ico ...

  9. 【翻译】对于Ext JS 5,你准备好了吗?

    原文:Are You Ready for Ext JS 5? Ext JS 5:准备升级 对于Ext JS 5加入Sencha的大家庭,我们感到非常高兴!作为一个主要版本,在Ext JS 5引入了一堆 ...

最新文章

  1. Oracle批量导出AWR报告
  2. Python语言学习:Python随机生成那些事之随机生成使用方法、案例应用之详细攻略
  3. Oracle 中 call 和 exec的区别
  4. python使用redis教程 敲黑板划重点
  5. [转载]关于webbrowser,innet,xmlhttp获取网页源码的比较!
  6. Django 组件- 中间件
  7. python自加1_python中有自增
  8. python数组_Python数组
  9. [LeetCode]168. Excel Sheet Column Title
  10. 基于etcd+confd通过nginx对docker服务混合注册发现详解
  11. h5页面 请在微信客户端打开链接_模拟微信接口时,提示“请在微信客户端打开链接”(转)...
  12. 2022-2027年中国OLED市场竞争态势及行业投资前景预测报告
  13. win10装linux双系统6,win10如何安装linux双系统
  14. 肌肤食品揭秘淘宝骗子经典伎俩
  15. python制作简单网页_怎么用python简单的制作一个网页
  16. WEP/WPA/WPA2/WPA3初识
  17. 5月Github上最热门的数据科学和机器学习项目TOP5
  18. 百度经纬度和google经纬度转换测试
  19. 硅谷最牛程序员,总是不经意间碾压众人
  20. 百度地图api实现轨迹运动效果

热门文章

  1. python之路---迭代器和生成器
  2. [快速] 一行指令暫時隱藏 Mac 桌面檔案 – 讓你凌亂的桌面不會被看見 - TechMoon 科技月球...
  3. 特斯拉上海超级工厂开工 预计今夏完成初期建设
  4. linux开发神器--Tmux
  5. 合肥云暨移动应用孵化基地全面运营,服务企业转型升级
  6. 关于 top、left 结合 translate 实现居中的原理探讨
  7. 网络安全渗透--判断网站使用何种网页语言,判断网站所用服务器
  8. 教你用netstat-实践案例
  9. HDOJ1871 无题
  10. 【干货分享】dos命令大全