lufy's legend
标题:
关于清空画面的疑问
[打印本页]
作者:
cheney28
时间:
2017-10-23 09:20
标题:
关于清空画面的疑问
本帖最后由 cheney28 于 2017-10-23 09:23 编辑
老大你好,
//清空背景层
function cleanBg(){
BGDiv.removeAllChild(); //移除所有子对象
BGDiv.die(); //移除所有事件监听
}
复制代码
这个清空画面函数里面的
removeAllChild()和
die()哪一个更需要先执行的?
我本来是先die()的,然后发现在有LListView对象的页面里不能离开页面,会提示ui.js找不到listObj.getItems.length
console.dir(List001); //LLLListView
console.dir(List001._ll_items); //Array[14]
console.dir(List001._ll_items.length); //14
console.dir(List001.getItems); //function LListView.getItems()
console.dir(List001.getItems.length); //0
//以下是控制台的唯一一条报错
//lufylegend.ui-0.14.1.min.js:1 Uncaught TypeError: Cannot read property 'length' of null
//LListView.die @ lufylegend.ui-0.14.1.min.js:1
//p.removeAllChild @ lufylegend-1.10.1.min.js:11
//cleanBg @ main.js:225
//NavToBag @ main.js:592
//MouseEventContainer._dispatchEvent @ lufylegend-1.10.1.min.js:11
//MouseEventContainer.dispatchEvent @ lufylegend-1.10.1.min.js:11
//MouseEventContainer.dispatchMouseEvent @ lufylegend-1.10.1.min.js:11
//LGlobal.mouseEvent @ lufylegend-1.10.1.min.js:11
//LGlobal.ll_mouseDown @ lufylegend-1.10.1.min.js:11
复制代码
然后我试着交换俩函数的位置,先执行
removeAllChild(),虽然也读不到length,但是页面可以正常清空。
而且除了有列表的页面之外,好像这俩执行顺序先后对我现在的游戏没有影响,那一般情况下是要把哪一个放前面?
作者:
lufy
时间:
2017-10-23 09:37
我的失误了,我在LListView的die中将列表的_ll_items设置了nul,所以你getItems获取到的列表就是null,所以 .length就出错了,你在使用.length之前,判断一下getItems获取到的列表是不是null,然后再使用.length就不会出错了,
另外,这两个函数都执行的时候,谁先谁后,执行的最终结果其实是一样的
作者:
cheney28
时间:
2017-10-23 13:46
了解,不影响使用的前提下绕开这个问题就好了。
能正常清空页面就OK
欢迎光临 lufy's legend (http://lufylegend.com/forum/)
Powered by Discuz! X2.5