免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3186 | 回复: 8
打印 上一主题 下一主题

大家看看这个句法transaction [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-30 15:26 |只看该作者 |倒序浏览
function createTable() {

        db.transaction(
                function(transaction){
                        transaction.executeSql(相应的各种参数)
               }
        );
       
}


db.transaction中的transaction与function(transaction)和transaction.executeSql中的transaction有什么联系?

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2009-09-30 15:36 |只看该作者
在线等 ~~~

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 2009-09-30 16:04 |只看该作者
没人回答吗?还是我哪里没有写清楚?~~

论坛徽章:
0
4 [报告]
发表于 2009-10-02 11:07 |只看该作者

这个是什么啊

是Orcale吗?

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 2009-10-11 11:42 |只看该作者
是HTML5 中的本地数据库

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
6 [报告]
发表于 2009-10-11 20:10 |只看该作者
LZ看手册的分析能力还有待提高很多啊,进步前景非常可观。

Executing queries
The database interface provides asynchronous access through a transaction paradigm:

transaction.executeSQL( SQLStatement, SQLParameters, ResultsetCallback, ErrorCallback )

...and this is how it looks in action:

db.transaction(function(tx)
  {   
    tx.executeSql('SELECT * FROM MyTable WHERE CategoryField = ?',
      [ selectedCategory ],
      function (tx, rs) { displayMyResult(rs); },
      function (tx, err) { displayMyError(err); } );
  });

This fetching example shows how to get data from the DB, or more generally: how to execute arbitrary SQL statements. In this example displayMyResult(rs) and displayMyError(err) are just placeholders for whatever you want to do with the result once it arrives.


你看的应该和上面的类似。

我们来分析:适当变化一下子,你更好理解:
function createTable() {

        db.transaction(
                function(t){
                        t.executeSql(相应的各种参数)
               }
        );
      
}

很明显,t.executeSql的t来自function(t)的t,两者等同,这个是基础知识,无法理解的先看一本基础资料,否则无法继续了。
function(t)这个t是函数的参数,也就是调用函数的时候传递什么就是什么,可以叫t,也可以叫阿猫阿狗,只有函数体内不跟着叫就成了。
db.transaction的参数,可以是函数,这里用的是js的匿名函数,所以直接function(t)了,调用的时候,会把db.transaction作为这个匿名函数的参数传递过去,作用上可以把t当作db.transaction来看待,就成了。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
7 [报告]
发表于 2009-10-12 16:33 |只看该作者

回复 #6 HonestQiao 的帖子

谢谢乔老板

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
8 [报告]
发表于 2009-10-12 16:37 |只看该作者
调用的时候,会把db.transaction作为这个匿名函数的参数传递过去,作用上可以把t当作db.transaction来看待,就成了。
这句是最有用的

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
9 [报告]
发表于 2009-10-12 16:39 |只看该作者
你的Executing queries
The database interface provides asynchronous access through a transaction paradigm:

transaction.executeSQL( SQLStatement, SQLParameters, ResultsetCallback, ErrorCallback )

...and this is how it looks in action:

db.transaction(function(tx)
  {   
    tx.executeSql('SELECT * FROM MyTable WHERE CategoryField = ?',
      [ selectedCategory ],
      function (tx, rs) { displayMyResult(rs); },
      function (tx, err) { displayMyError(err); } );
  });

This fetching example shows how to get data from the DB, or more generally: how to execute arbitrary SQL statements. In this example displayMyResult(rs) and displayMyError(err) are just placeholders for whatever you want to do with the result once it arrives.
这段是从哪里看到的?能不能给个连接
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP