【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. Ubuntu-16.04安装Xdebug-2.2.5及相关介绍

    Xdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),可以用来跟踪,调试和分析PHP程序的运行状况.在日常开发中,我们会使用如 print_r() var_dump()等函数来进行调 ...

  2. zabbix获取到的数值自定义单位

    1) 查找php文件 # find / -name "func.inc.php" /usr/share/zabbix/include/func.inc.php 2)修改文件 #vi ...

  3. debug 英文翻译

    declaration of 'int a' shadows a parameter :函数参数里,已经有这两个名称的变量了,指定义了同名的参数,造成了隐藏. expected primary-exp ...

  4. 递归输入与引用传值(UVa839 Not so Mobile)

    题目的大意是一个树形天平,输入给出样例的个数,然后空一行,每行4个数W1,D1,W2,D2,分别代表天平左侧的重量.力臂和天平右侧的重量.力臂.如果W1或者W2为0,则代表该节点有左子树或右子树,如果 ...

  5. 集训考试题(CF510C Fox And Names的简化版)

    题目描述给定n个由小写字母组成的字符串,请你求出一个字母表顺序,使得这n个字符串是按照字典序升序排列的,数据保证存在合法的字母表顺序.如果存在多个解,输出字典序最小的那个. 输入格式第一行一个整数n. ...

  6. Codeforces #427 Div2 D

    #427 Div2 D 题意 给出一个字符串,求它的子串中为 \(k-palindrome\) 的个数. \(1-palindrome\) 要求是一个回文串. \(k-palindrome (k &g ...

  7. 前端设计师必须知道的10个重要的CSS技巧

    对于一个初入门的前端设计师,在设计修改网站前端的时候,我们需要编写一些CSS.JS的内容达到界面效果.今天分享10个对于前端设计师来说重要的CSS技巧,这也是我在给许多客户做网站的过程当中总结出来的. ...

  8. 软件配置篇-MySQL下载及安装

    1.进入MySQL官网下载 下载地址:https://dev.mysql.com/downloads/mysql/ 选择合适的版本下载. 2.安装MySQL 解压后文件夹一般名为:mysql-x.x. ...

  9. 图像视图-ImageView

    (一) 知识点: (1)imageView.setImageAlpha(Alpha):设置图片透明度 (2)在布局imageView中设置图片位置:android:scaleType="ce ...

  10. android连接Mysql数据库之JDBC方式

    一.创建一个数据库和若干表,并导入相关信息.这里以我之前使用的一个图书系统的数据库为例子. 首先假设已经安装并配置好Mysql.(建议大家安装WAMP,也就是安装完这个,就相当于安装了Mysql,PH ...