我使用self.getQuestion = function(questionNumber, sectionId) {
var deferred = $q.defer();
var question = {};
question.hasCounter = false;
question.hasDetail = false;
question.hasSubSection = false;
console.log('SELECT * FROM question WHERE question_type = 1 AND question_number = '+ questionNumber +' AND section_id = ' + sectionId);
DB.query('SELECT * FROM question WHERE question_type = 1 AND question_number = ? AND section_id = ?', [questionNumber, sectionId])
.then(function(result){
console.log(result);
question.main = DB.fetch(result);
console.log(question.main);
Answer.getAnswer(question.main.question_id).then(function(answer) {
question.main.answer = answer;
//Check if this question has any counter question
console.log('SELECT * FROM question WHERE question_type = 2 AND parent_id = ' + question.main.question_id);
DB.query('SELECT * FROM question WHERE question_type = 2 AND parent_id = ?', [question.main.question_id])
.then(function(result){
console.log(result);
if(result.rows.length == 0)
{
question.hasCounter = false;
//Check if this question still has any subsection (s)
console.log('SELECT * FROM question WHERE section_id = '+ sectionId +' AND question_number = '+ question.main.question_number +' AND question_number_section != ""');
DB.query('SELECT * FROM question WHERE section_id = ? AND question_number = ? AND question_number_section != ""', [sectionId, question.main.question_number])
.then(function(result){
if(result.rows.length == 0)
{
question.hasSubSection = false;
deferred.resolve(question);
}
else
{
question.hasSubSection = true;
question.sub = DB.fetchAll(result);
console.log(question.sub);
for (var i in question.sub)
{
console.log("i+"+i);
(function(j)
{
console.log("j+"+j);
question.sub[j].answer = {};
Answer.getAnswer(question.sub[j].question_id).then(function(res) {
question.sub[j].answer = res;
if(j == (question.sub.length-1))
{
deferred.resolve(question);
}
})
})(i);
};
}
});
}
else
{
question.hasCounter = true;
question.counter = DB.fetch(result);
Answer.getAnswer(question.counter.question_id).then(function(answer) {
question.counter.answer = answer;
});
//Get detail question
DB.query('SELECT * FROM question WHERE question_type = 3 AND parent_id = ?', [question.counter.question_id])
.then(function(result){
question.detail = DB.fetchAll(result);
question.hasDetail = true;
for (var j in question.detail)
{
(function(i)
{
question.detail[i].answer = {};
console.log(question.detail[i].question_id);
Answer.getDetailAnswer(question.detail[i].question_id, i).then(function(res) {
console.log(res);
question.detail[i].answer = res;
if(j == (question.detail.length-1))
{
deferred.resolve(question);
}
})
})(j);
};
});
}
});
});
});
return deferred.promise;
};
self.getAnswer = function(questionId) {
var deferred = $q.defer();
DB.query('SELECT * FROM answer WHERE question_id = ?', [questionId])
.then(function(result){
answer = DB.fetch(result);
if(answer && answer.answer_type == 3)
{
deferred.resolve(answer);
}
//Get Answer Option
if(answer)
{
DB.query('SELECT * FROM answer_option WHERE answer_id = ? ORDER BY option_code', [answer.answer_id])
.then(function(result){
answer.answerOptions = DB.fetchAll(result);
deferred.resolve(answer);
});
}
});
return deferred.promise;
};
self.getDetailAnswer = function(questionId, index) {
var deferred = $q.defer();
var answer = [];
DB.query('SELECT * FROM answer WHERE question_id = ?', [questionId])
.then(function(result){
answer[index] = DB.fetch(result);
if(answer[index] && answer[index].answer_type == 3)
{
console.log("Resolved: " + answer[index].answer_id);
deferred.resolve(answer[index]);
}
//Get Answer Option
if(answer[index])
{
DB.query('SELECT * FROM answer_option WHERE answer_id = ? ORDER by option_code', [answer[index].answer_id])
.then(function(result){
//console.log(answer.answer_id + " / " + questionId);
answer[index].answerOptions = DB.fetchAll(result);
deferred.resolve(answer[index]);
console.log("Resolved 2: " + answer[index].answer_id + " / " + questionId);
});
}
});
return deferred.promise;
};
实现了侧边菜单应用,并且工作正常。在我的SWRevealViewController
我要加载子视图。当我点击显示切换按钮时,我想删除该子视图。因为如果我打开那个子视图并且没有关闭,如果我点击了revealtoggle按钮,它就会出现在侧面菜单中。如果我选择FrontViewController
上面的相同菜单项加载子视图(之前它还没有关闭)。那么当出现侧面菜单时,如何删除此子视图。我做了这样的事。但是这个代表没有在FrontViewcontroller
ViewController
请帮帮我。 感谢