如何在sqlite数据库离子中转储json数据

时间:2016-10-06 11:19:34

标签: json sqlite ionic-framework

我想在sqlite ionic中插入和检索具有多个值的JSON数据。我还想在listview中显示数据。

var query="SELECT * from triptable";
$cordovaSQLite.execute(db, query,[]).then(function(res) {
  if (res.rows.length>0) {
    console.log("Values are:"+tripData);
    for (var i = 0; i < res.rows.length; i++) {
       $scope.login.push({
         tripId:res.rows.item[i].tripId,
         tripReqId:res.rows.item[i].tripReqId,
         tripProjectCode:res.rows.item[i].tripProjectCode,
         tripProjectName:res.rows.item[i].tripProjectName,
         tripTravellerName:res.rows.item[i].tripTravellerName,
         tripStartDate:res.rows.item[i].tripStartDate,
         tripEndDate:res.rows.item[i].tripEndDate,
         tripOriginCity:res.rows.item[i].tripOriginCity,
         tripTrNo:res.rows.item[i].tripTrNo,
         tripDestiCity:res.rows.item[i].tripDestiCity,
         tripFeedBAckProvided:res.rows.item[i].tripFeedBAckProvided,
         tripStatus:res.rows.item[i].tripStatus
       });
    }
  }
  else {
    console.log("No trips found");
  }
 }, function (err) {
     console.error(err);
 });

1 个答案:

答案 0 :(得分:0)

使用JSON.stringify转换它们的排列json数据。然后显示列表中的数据

$scope.login = JSON.stringify($scope.login);

列出

<div ng-repeat="log in login">
  {{login.tripId}}
</div>