简体   繁体   English

Google关闭:如何在元素上设置可见

[英]Google Closure: How do I setVisible on an Element

While rendering the page first time I create a toolbar using goog.ui.Toolbar . 第一次渲染页面时,我使用goog.ui.Toolbar创建了一个工具栏。 I later add some buttons to it. 稍后,我向其中添加一些按钮。 Also I hide a few buttons. 我也隐藏了一些按钮。

this.mainToolbar = new components.ui.Toolbar();
this.addChild(this.mainToolbar);

var mlSelectBtn = new components.ui.ToolbarButton(content);
mlSelectBtn.setId("select");
this.mainToolbar.addChild(mlSelectBtn, true); 

var mlUnSelectBtn = new components.ui.ToolbarButton(content);
mlUnSelectBtn.setId("unselect");
this.mainToolbar.addChild(mlUnSelectBtn, true); 
mlUnSelectBtn.setVisible(false);

Now when I click a few other buttons on my application I want to hide select button and unhide unselect button. 现在,当我在应用程序上单击其他几个按钮时,我想隐藏选择按钮并取消隐藏取消选择按钮。 I try to do this 我尝试这样做

var temp = document.querySelector("[id=unselect]");
temp.setVisible(true);

I get an error saying setVisible is not a function. 我收到一个错误消息,说setVisible不是一个函数。 How do I set the visible back to true ? 如何将visible设置为true?

The result of the querySelector method is a DOM element, but to call setVisible you need a reference to the ToolbarButton ( mlUnSelectBtn , above). querySelector方法的结果是一个DOM元素,但是要调用setVisible您需要引用ToolbarButton (上面的mlUnSelectBtn )。 You will need to store a reference to mlUnSelectBtn somewhere which can be accessed by the code which resets the visibility. 您将需要存储对mlUnSelectBtn的引用,该引用可以通过重置可见性的代码进行访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为Google Closure Compiler启用日志记录? - How do I enable logging for Google Closure Compiler? 如何迭代Google Closure中的枚举值? - How do I iterate over enum values in Google Closure? 我如何用闭包解决这个问题? - How do I solve this with closure? 如何使用Google的Closure库获取DOM元素的当前视口位置? - How do you get the current viewport position of a DOM element using Google's Closure library? 如何在Google Closure编译器中为对象类型指定@param @return? - How do I specify @param @return for object type in Google Closure Compiler? 如何使用外部Javascript库(如jQuery)重命名Google Closure样式表? - How do I use Google Closure Stylesheet renaming with an external Javascript Library such as jQuery? 命令行 Google Closure 提供的标准 extern 有哪些,如何通过 Java 接口获取? - What are the standard externs provided by the command line Google Closure, and how do I get them through the Java interface? 如何使用Google Closure编译器删除未使用的JavaScript代码? - How do I use Google Closure compiler to remove unused JavaScript code? 如何使用Google Closure编译器使巨大的javascript文件更加有效和可维护? - How do I use google closure compiler to make a gigantic javascript file more efficient and maintainable? 使用Google闭包模板时,如何在Soy文件中迭代对象? - How do I iterate over an object within a Soy file when using Google closure templates?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM