当前位置: 首页 > news >正文

Wt::JSlot Class Reference

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

Wt::JSlot Class Reference
Signal/slot system

A slot that is only implemented in client side JavaScript code. More...

【JSlot是一种槽,只被客户端JavaScript代码(去)实现】

#include <Wt/WJavaScript>

List of all members.

Public Member Functions


 JSlot (WWidget *parent=0)
 Constructs a JavaScript-only slot within the parent scope. 
 JSlot (const std::string &javaScript, WWidget *parent=0)
 Constructs a JavaScript-only and sets the JavaScript code. 
 ~JSlot ()
 Destructor. 
void setJavaScript (const std::string &javaScript)
 

Sets or modify the JavaScript code associated with the slot.

【设置或修改与本槽关联的JavaScript代码】 

void exec (const std::string &object="null", const std::string &event="null")
 

Executes the JavaScript code.

【执行由setJavaScript()设置的JavaScript代码】 

std::string execJs (const std::string &object="null", const std::string &event="null")
 

Returns a JavaScript statement that executes the slot. 

Detailed Description

A slot that is only implemented in client side JavaScript code.

This class provides a hook for adding your own JavaScript to respond to events.

【JSlot提供了hook机制,允许开发者添加自定义的JavaScript代码去对事件作出反应。】

Carefully consider the use of this. Not only is writing cross-browser JavaScript hard and tedious, but one must also be aware of possible security problems (see further), and ofcourse, the event handling will not be available when JavaScript is disabled or not present at all.

If you wish to add client side event handling, with automatic fall-back to server-side event handling and without writing JavaScript code with the associated risks and problems, consider using stateless slot implementations instead (see WObject::implementStateless())

For some purposes, stateless slot implementations are not sufficient, since they do not allow state inspection. At the same time, the non-availability in case of disabled JavaScript may also be fine for some non-essential functionality (see for example the WSuggestionPopup widget), or when you simply do not care. For these situations a JSlot can be used to add client-side event handling.

The JavaScript code may be set (or changed) using the setJavaScript() method which takes a string that implements a JavaScript function with the following signature:

function(sender, event) {

// handle the event, and sender is a reference to the DOM element

// which captured the event (and holds the signal). Therefore it

// equivalent to the sender for a normal %Wt slot.

// You can prevent the default action using:

${WT_CLASS}.cancelEvent(event);

// (where ${WT_CLASS} should be the value of the WT_CLASS define

}

In the JavaScript code, you may use WWidget::jsRef() to obtain the DOM element corresponding to any WWidget, or WWidget::id() to obtain the DOM id. In addition you may trigger server-side events using the JavaScript WtSignalEmit function (see JSignal documentation). That's how far we can help you. For the rest you are left to yourself, buggy browsers and quirky JavaScript (http://www.quirksmode.org/ was a reliable companion to me) -- good luck.

Note that the slot object needs to live as long as you want the JavaScript to be executed by connected signals: when the slot is destroyed, the connection is destroyed just as with other signal/slot connections where the target object is deleted. This means that it is (almost?) always a bad idea to declare a JSlot on the stack.


转载于:https://my.oschina.net/zhmsong/blog/38700

相关文章:

  • 面试中经常遇到的SQL
  • linux小知识
  • 部署 Lync 2010 移动电话(Internal)
  • silverlight 动态类创建和使用
  • CNZZ统计独立访客、ip、pv
  • Bash的陷阱
  • liunx下的find 参数及用法
  • PHP中去除换行解决办法小结(PHP_EOL)
  • arp简析
  • 数字签名与加密解密
  • [医疗]DICOM VR数据类型表
  • 马化腾创业前传:50万创业资金自炒股得来
  • TX Text Control文字处理教程(8)使用超链接
  • mongodb
  • Navicat for MySQL之HTTP和SSH远程连接数据库
  • 9月CHINA-PUB-OPENDAY技术沙龙——IPHONE
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • create-react-app做的留言板
  • CSS魔法堂:Absolute Positioning就这个样
  • DOM的那些事
  • iOS动画编程-View动画[ 1 ] 基础View动画
  • laravel with 查询列表限制条数
  • Material Design
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • react-core-image-upload 一款轻量级图片上传裁剪插件
  • ReactNativeweexDeviceOne对比
  • RxJS 实现摩斯密码(Morse) 【内附脑图】
  • Spring Security中异常上抛机制及对于转型处理的一些感悟
  • tab.js分享及浏览器兼容性问题汇总
  • vue2.0一起在懵逼的海洋里越陷越深(四)
  • vue-cli3搭建项目
  • 高性能JavaScript阅读简记(三)
  • 为视图添加丝滑的水波纹
  • 要让cordova项目适配iphoneX + ios11.4,总共要几步?三步
  • 译自由幺半群
  • 转载:[译] 内容加速黑科技趣谈
  • 不要一棍子打翻所有黑盒模型,其实可以让它们发挥作用 ...
  • 函数计算新功能-----支持C#函数
  • 新海诚画集[秒速5センチメートル:樱花抄·春]
  • ###STL(标准模板库)
  • #pragma multi_compile #pragma shader_feature
  • #我与Java虚拟机的故事#连载02:“小蓝”陪伴的日日夜夜
  • #我与Java虚拟机的故事#连载04:一本让自己没面子的书
  • (12)Linux 常见的三种进程状态
  • (20)目标检测算法之YOLOv5计算预选框、详解anchor计算
  • (27)4.8 习题课
  • (cljs/run-at (JSVM. :browser) 搭建刚好可用的开发环境!)
  • (DenseNet)Densely Connected Convolutional Networks--Gao Huang
  • (附源码)node.js知识分享网站 毕业设计 202038
  • (学习日记)2024.04.04:UCOSIII第三十二节:计数信号量实验
  • (一)spring cloud微服务分布式云架构 - Spring Cloud简介
  • (一)基于IDEA的JAVA基础1
  • (转)3D模板阴影原理
  • (转)四层和七层负载均衡的区别
  • .NET CF命令行调试器MDbg入门(三) 进程控制