Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提供更稳定的DOM元素id生成算法 #80

Closed
otakustay opened this issue May 25, 2013 · 2 comments
Closed

提供更稳定的DOM元素id生成算法 #80

otakustay opened this issue May 25, 2013 · 2 comments
Assignees

Comments

@otakustay
Copy link
Member

现在虽然getGUID()是稳定的,在整个代码一点不变的情况下生成的对应的DOM的id也是稳定的。但是一但在前面加一个控件之类的,后面的所有控件对应的DOM的id都会变化,直接导致很多依赖id的自动化脚本要重写。

需要一个更稳定的,不依赖于getGUID的算法。

@otakustay
Copy link
Member Author

解决方案:

  1. ViewContext在构建的时候可以传id进来,默认的那个的id为default,这样就稳定了。其它的ViewContext的id由使用的系统保证稳定。
  2. 生成DOM id的算法与viewContext.id挂钩。

这个方案生成的DOM id与viewContext相关,因此需要ViewContext在设置后就不得变化,不然会有很多获取子DOM的方法失效,这个问题会很严重,所以干脆在标准上让viewContext属性在render之后只读好了

@otakustay
Copy link
Member Author

现在通过缓存把初始时的viewContext.id挂在了domIDPrefix属性下,允许ViewContext的变化了。

不过最好还是别推荐去变ViewContext,这个东西的设定本身不是为了变来变去而产生的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant