【1】 调式qweb模板时, 可以脱离openerp环境

阅读一下openerp目录 qweb目录中的几个html文件,可以作为起步

在浏览器下, 可以这样运行这些文件

http://127.0.0.1:8069/web/static/lib/qweb/qweb-benchmark.html

http://127.0.0.1:8069/web/static/lib/qweb/qweb-test.js.html

【2】qweb模板的格式如果不符合xml规范, 浏览器显示空白, 浏览器的控制台中会显示如下提示

Uncaught Error: QWeb2: This page contains the following errors:error on line xxx at column yyy:

然后是具体的错误原因。比如

Opening and ending tag mismatch: aaa  line nnn and bbb

Specification mandate value for attribute ccc

【3】在模板中增加如下指令, 可在浏览器的控制台上输出变量内容

〈t t-log="变量名称" />

当使用多个t-log时, 控制台中输出的变量内容会引起混淆, 这时可再增加如下语句

〈t t-log=" '变量名称的说明' " /> 

【4】在模板中增加如下指令, 可在qweb的编译模板过程中进入断点语句,

〈t t-debug="随便什么东东" /> 

这时, 我们可以在控制台的源码页签中看到编译的中间过程,

在控制台下, 使用console.log(dict) 可以看到传入的所有参数

使用console.log(r) 可以看到输出中间结果

官方文档上 介绍的使用方法 〈t t-debug />  ,如果后面不随便添加些什么东东, 会出现如下错误

Specification mandate value for attribute t-debug

【5】模板文件示例  (在qweb目录下, 文件名为 laoliu.xml)

如下是官网上web文档中的例子, 增加了t-log和t-debug语句

〈templates>
〈div t-name="example_template" t-attf-class="base #{cls}">
〈t t-log="'in example_template, value of [items]:'" />
〈t t-log="items" />
〈h4 t-if="title"> 〈t t-esc="title"/> 〈/h4>
〈ul>
〈li t-foreach="items" t-as="item" t-att-class="item_parity">
〈t t-call="example_template.sub">
〈t t-set="arg" t-value="item_value"/>
〈/t>
〈/li>
〈/ul>
〈t t-debug="随便什么东东" />
〈/div> 〈t t-name="example_template.sub">
〈t t-log="'in example_template.sub, value of [arg]:'" />
〈t t-log="arg" />
〈t t-esc="arg.name"/>
〈dl>
〈t t-foreach="arg.tags" t-as="tag" t-if="tag_index lt 5">
〈dt> 〈t t-esc="tag"/> 〈/dt>
〈dd> 〈t t-esc="tag_value"/> 〈/dd>
〈/t>
〈/dl>
〈/t>
〈/templates>

【6】 程序示例  (在qweb目录下, 文件名为 laoliu.html)

访问方法:http://127.0.0.1:8069/web/static/lib/qweb/laoliu.html

〈!doctype html>
〈html>
〈head>
〈script src="../jquery/jquery-1.8.3.js"> 〈/script>
〈script type="text/javascript" src="qweb2.js"> 〈/script>
〈script>
var laoliu_data={
"class1": "foo",
"title": "Random Title",
"items": [
{ "name": "foo", "tags": {"bar": "baz", "qux": "quux"} },
{ "name": "Lorem", "tags": {
"ipsum": "dolor",
"sit": "amet",
"consectetur": "adipiscing",
"elit": "Sed",
"hendrerit": "ullamcorper",
"ante": "id",
"vestibulum": "Lorem",
"ipsum": "dolor",
"sit": "amet"
}
}
]
}; QWeb = new QWeb2.Engine();
QWeb.debug = true;
QWeb.add_template('laoliu.xml');
template='laoliu.xml';
result=QWeb.render('example_template', laoliu_data );
$(document).ready(function () {
$('.placeholder').append(result);
});
〈/script> 〈/head>
〈body>
〈div class="placeholder">
〈/div>
〈/body>
〈/html>

【7】t-debug的运行结果

(function(dict
) { var context = { engine : this, template : 'example_template' };
dict = dict || {};
dict['__template__'] = 'example_template';
var r = [];
r.push(' 〈div');
r.push(context.engine.tools.gen_attribute(['class', ('base ' + (dict['cls']))]));
r.push('> ',
'n ');
console.log('in example_template, value of [items]:');
r.push('n ');
console.log(dict['items']);
r.push('n ');
if (dict['title']) {
r.push(' 〈h4> ');
r.push(context.engine.tools.html_escape(dict['title']));
r.push(' 〈/h4> ');
}
r.push('n 〈ul> ',
'n ');
context.engine.tools.foreach(context, dict['items'], 'item', dict, function(context, dict) {
r.push(' 〈li');
r.push(context.engine.tools.gen_attribute(['class', (dict['item_parity'])]));
r.push('> ',
'n ');
r.push(context.engine.tools.call(context, 'example_template.sub', dict, '', function(context, dict) {
var r = [];
r.push('n ');
dict['arg'] = (dict['item_value']);
r.push('n ');
return r.join('');
}));
r.push('n 〈/li> ');
});
r.push('n 〈/ul> ',
'n ');
debugger;
r.push('n 〈/div> '); return r.join('');
})

openerp所用QWEB2的调试笔记的更多相关文章

  1. Tomcat调试笔记

    调试笔记 在使用Tomcat过程中经常碰到问题,导致tomcat启动失败.如下↓ 由于报错太过笼统,我根本无法找出错误.后来我切换到Console视图下,看到了如下错误信息. 根据报错信息,错误原因是 ...

  2. JavaScript特效(调试笔记)

    JavaScript特效 一.在网页上显示当前的时间日期,例如:“2016年3月26日 星期六”. js源代码: function getTime() { var today = new Date() ...

  3. USB wifi调试笔记

    本文以realtek 8192CU WiFi模块为例,介绍USB wifi在Jelly Bean 4.1的调试笔记. 1.WIFI打不开现象概述 WiFi打不开是指您在UI的settings下选中Wi ...

  4. ida动态调试笔记

    ida动态调试笔记 目标文件:阿里安全挑战赛的第二题 点击打开链接 使用环境:ida6.8点击打开链接,adt bundle点击打开链接 首先打开avd安卓模拟器,界面如下: 在dos下运行adb命令 ...

  5. modbus-poll和modbus-slave工具的学习使用——modbus协议功能码3的解析(及欧姆龙温控器调试笔记)

    最近的项目中使用到了欧姆龙的温控器,里面有很多的通信方式,我们使用的常见的modbus——RTU方式,其他方式我们不使用,其中通信手册上面有很多通信的实例,欧姆龙modbus还区分4字节模式和2字节模 ...

  6. GDB调试笔记

    参考资料:GDB调试精粹及使用实例 # 调试实例 #include <iostream> #include <cstring> using namespace std; ][] ...

  7. 《C#并行编程高级教程》第7章 VS2010任务调试 笔记

    没有什么好说的,主要是将调试模式下的Parallel Tasks窗体和Parallel Stacks窗体.折腾一下应该比看书效果好.(表示自己没有折腾过) 另外值得注意的是,主线程不是一个任务.所以主 ...

  8. SIM900A模块HTTP相关调试笔记

    SIM900A模块使用笔记 更新2018-12-8 正常工作状态: 接线方法: 首先将 AT 写入字符串输入框,然后点击 发送.因为模块波特率默认是 9600,所以两条指令的显示都是没有问题的:如果将 ...

  9. 博世传感器调试笔记(一)----加速度传感器BMA253

    公司是bosch的代理商,最近一段时间一直在公司开发的传感器demo板上调试bosch sensor器件.涉及到的器件有7,8款,类型包括重力加速度.地磁.陀螺仪.温度.湿度.大气压力传感器等.在调试 ...

随机推荐

  1. 微信支付报错:app没有获取微信支付权限

    调试微信支付的时候报错: Array( [return_code] => FAIL [return_msg] => 您没有APP支付权限) 查询了,发现自己将之前的公众号支付的APPID一 ...

  2. Vmware esxi开启snmp服务

    https://jingyan.baidu.com/article/9f7e7ec055c4c86f28155435.html http://pubs.vmware.com/vsphere-50/in ...

  3. scrapy模拟请求头

    import random USER_AGENT_LIST=[ 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, lik ...

  4. lunux多线程编程

    1.进程与线程 1)用户空间角度: 进程:fork()创建进程,在创建时,重新申请了内存空间,copy了父进程的所有信息. 线程:pthread_create()创建进程时,只申请自己的栈空间. 2) ...

  5. POJ1330 Nearest Common Ancestors(最近公共祖先)(tarjin)

    A - Nearest Common Ancestors Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld &am ...

  6. ReentrantReadWriteLock (读写锁)源码分析

    关于AbstractQueuedSynchronizer中的独占锁,请参考ReentrantLock(http://www.cnblogs.com/bjorney/p/8040085.html) 1. ...

  7. ubuntu下python3及idle3的安装

    一.使用以下命令检查自己的系统下是否有python3 python3 --version 如果出现类似“command not found",则说明你需要安装python3.如果能够出现py ...

  8. fidder模拟post提交到PHP遇到的问题

    http头必须带上Content-type: application/x-www-form-urlencoded  之后 ,php 才能接收到post数据 1. 用php://input可以很便捷的取 ...

  9. FTTB FTTC FTTH FTTO FSA

    FTTB Fiber to The Building 光纤到楼 FTTC Fiber to The Curb 光纤到路边 FTTH Fiber to The Home 光纤到家 FTTO Fiber ...

  10. How to enable Hibernate option in windows 2008 R2 server?

    http://velshare.blogspot.com/2013/02/how-to-enable-hibernate-option-in.html 1) To enable the Hiberna ...