| NuttyCoder's profile初级程序员BlogLists | Help |
|
初级程序员ROOKIE: a PErSon whO iS nEW TO an OrgANiZAtION oR An ActiVITy 5/6/2008 NET USENET USE 4/21/2008 有关 JavaScript 及其它的一点点1、对其它对象的临时引用尽量不要用对象的属性,因为会长时间的占用资源,只有当对象消亡的时候才会释放。一般来说用var定义临时变量就好了。(当然更不能不用var而成为默认的全局变量......= =) 2、不要乱用alert,调试的时候加上的try...catch、alert等代码要在发布或调试基本完成后及时清理。 3、(编码习惯)用空格缩进,不要用Tab。Tab在不同的环境下的解释是不同的,可能造成排版的混乱。 4、(GI)少用Layout,尽量用Block布局。Block在界面变化中耗费较多时间,一个Layout通常意味着存在三个Block,改为一个Block,可以节省两个Block。 3/28/2008 Use XSLT to Dispose Data in MatrixBoth Matrix and Matrix.Column have a property named "jsxvaluetemplate". The value of this property should be a XSLT. JSX engine transform the CDF with this XSLT. So, sometimes we could dispose data in matrix with this property.
For example, the XSLT above will judge "property1" and "property2", only if they are all true, a "remove" link would be shown. "@property1" is a way to quote property "property1" of the record, while "{@property3}" is another way, in string argument, maybe. (I'm not clear on it now.) Sometimes we have to use data in JavaScript, but not only in CDF. In this condition, we could split the XSLT to some joint strings, then save as a JSS record, which is set to be evaluated. So each part of the XSLT could be replace with a section of JavaScript. Following is the value of "jsxtext" in a JSS record:
There are 3 parts in it. The second one is JavaScript code and used for getting data in JS. Notify: "'" should be changed to "\'" when in JS string. 3/26/2008 Replace String whit Regular Expression in EditplusSometimes we need to replace strings in the same pattern in Editplus. For example, I have to add post-fix to "jsxname" attribute for every component in a UI file(XML) just now. These attributes appear as '<record jsxname="......">'. Pattern: jsxname="([^"]*)" [^"]: any charactor except ". [^"]*: a string without ". (): Affects evaluation order of expression and also used for tagged expression. Replace With: jsxname="\1_100" \1: evaluate [^"]* in (). 用PubSub传递List-Details形式的消息List-Details是一种很常见的界面表现形式。页面载入时,List首先被显示。当用户点击某条记录时(或其它动作),该条记录相关的Details显示出来。SPM的某些部分中,PubSub被用来完成List-Details消息的传递。 例如在Rule Library中(文件位于rule/library/),当用户选择一条记录时,会触发RuleLibMaster中的publishSelect。此函数将必要的信息装入Message并publish。这条消息在RuleLibrary和RuleLibDetail中分别被订阅,他们会先后(?)先后接收到消息。作为顶层框架,RuleLibrary会检查右侧Detail Panel是否已经被载入,如果没有,RuleLibrary会将该Components载入。随后(?)RuleLibDetail会分析Message,并将Message中的Record信息显示在Detail Panel上。 我在windowShadow的Alert中仿照了Rule Library中的这种处理方式。由List publish消息,顶层框架订阅消息装载Panel,Details Panel订阅消息并显示信息。 List-Details形式的消息比较单纯,所以直接调用Detail Panel的相关函数并通过参数传递信息并不显得复杂。但是更多时候,PubSub可以使程序逻辑更清晰。从设计的角度看,PubSub机制为不同模块之间实现了更松散的耦合。据说PubSub使用全局变量的设计会消耗更多的内存,是这种方式的一个弊端,及时的unsubscribe也许可以缓解这个问题。 |
||||
|
|