的index.html
<div class="test" ng-controller="Ctrl">
<button ng-click="removeTask(10);">remove</button>
<div>
app.js
app.controller('Ctrl', function($scope) {
$scope.removeTask = function(taskId) {
alert("Task Id is " + taskId);
};
var statement = "";
db.transaction(function (tx) {
//tx.executeSql('DROP TABLE IF EXISTS test_table');
statement = "select * from objects where o.TYPES=' + taskId' GROUP BY objectid";
alert
消息完美无缺,但当我尝试在taskId
语句中使用变量select
时,它不起作用。
答案 0 :(得分:1)
app.controller('Ctrl', function($scope) {
$scope.removeTask = function(taskId){
alert("Task Id is "+taskId);
$scope.taskId = taskId;
};
var statement = "";
db.transaction(function (tx) {
//tx.executeSql('DROP TABLE IF EXISTS test_table');
statement = "select * from objects where o.TYPES='+$scope.taskId+' GROUP BY objectid";
请注意,您必须将任务ID分配给范围变量以便稍后使用。
答案 1 :(得分:0)
您需要在函数内部创建db事务。
app.controller('Ctrl', function($scope) {
var statement = "";
$scope.removeTask = function(taskId) {
alert("Task Id is " + taskId);
db.transaction(function (tx) {
//tx.executeSql('DROP TABLE IF EXISTS test_table');
statement = "select * from objects where o.TYPES='+taskId' GROUP BY objectid";
};
};
taskId
等函数参数仅在函数内可用。