angularjs - AngularJs + Sqlite-在sqlite回调函数中填充变量

标签 angularjs sqlite cordova onsen-ui

我在sqlite回调函数中填充变量时遇到问题。那么如何使该变量填充?因为我想从查询中返回值。

这是我的代码。

情况一:

module.controller('MasterController7', function($scope, $data) {
   var hihi = [];
   $scope.queryResult = function() {

		database = window.openDatabase("Apps", "1.0", "Apps Database", 200000);
		database.transaction(function(tx){
		   var sql = "";
					
		   tx.executeSql(sql, [], 
		     function(tx, response)
		     { 	
                //hihi is not populated, the query ran successfuly.
			    hihi.push({title:'title',label:'label',desc:'desc'});
		     }, 
		     function(err)
		     {
			     //alert('aaaaaaa');
		     }
          );
        }, errorDB, successDB);
				
    };
			
	$scope.queryResult(); 
	$scope.items = hihi; 
   });

<ons-list ng-controller="MasterController7">
        <ons-list-item modifier="chevron" class="item" ng-repeat="item in items" ng-click="menu.setMainPage('favoritesurah.html', {closeMenu: true}); showDetail($index, item.title)">
          <ons-row>
            <ons-col width="60px"> 
              <div class="item-thum"></div>
            </ons-col>
            <ons-col>
              <header>
                <span class="item-title">{{item.title}}</span>
                <span class="item-label">{{item.label}}</span>
              </header>
              <p class="item-desc">{{item.desc}}</p>
            </ons-col>
          </ons-row>                          
        </ons-list-item>
      </ons-list>





p / s:即时通讯使用Onsen UI。

最佳答案

要获取查询结果,应将响应对象替换为$ scope对象
并且您应该执行$ scope。$ apply方法,因为事务回调已超出
AngularJS管理。

例如,executeSql回调是

                tx.executeSql(sql, [], 
                    function(tx, response)
                    {   
                        for (var i=0; i<response.rows.length; i++ ) {
                            var row = response.rows.item(i);
                            hihi.push({title:row.id,label:row.label,desc:row.name});
                            $scope.items = hihi;
                            $scope.$apply();
                        }                  
                    }, 
                    function(err)
                    {
                        //alert('aaaaaaa');
                    }
                );

关于angularjs - AngularJs + Sqlite-在sqlite回调函数中填充变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26088741/

相关文章:

javascript - angularjs:如何禁用特定元素的指令

javascript - 如何制作 JSON 的单独副本并阻止它在 angularjs 中被修改?

ios - 每次架构更改时我都需要打开和关闭连接吗?

android - PhoneGap (Android) 删除目录

javascript - 如何在 ios 手机 phonegap 编程中处理呼出和呼入电话的应用程序?

ios 在状态 "Preparing for Submission"时将应用程序从一个帐户转移到另一个帐户

angularjs - Angular ng-animate 1.3.* 导致 ng-class inside 指令出现意外行为

javascript - AngularJs - 使用 ng-init 时遇到问题

c# - 计数SQL查询未返回期望值

python - 将函数值插入 SQLite 数据库