-
Notifications
You must be signed in to change notification settings - Fork 0
/
current.html
85 lines (74 loc) · 2.93 KB
/
current.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>调当前题目</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.css">
</head>
<body>
<div class="container row">
<div class="col-xs-8 col-xs-offset-2">
<div class="form-group">
<select id="selectTitle" class="form-control">
</select>
</div>
<div class="form-group">
<button id="submitTitle" class="btn btn-default">选为当前题目</button>
</div>
</div>
</div>
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.5.4.js"></script>
<script>
(function () {
AV.initialize("89jnijh7ho5qm7a4bfgolekx673oof4se568f5y3g9ctudlr", "08rpae5q24x7gll6cwyh1jsbqpam02qx8nn06rjg23pdm76n");
var currentData = AV.Object.extend("Question");
var getAll = new AV.Query(currentData);
getAll.find().then(function (all) {
var html = '';
all.forEach(function (e) {
var selected = e.attributes.isCurrent ? 'selected' : '';
html += '<option value="' + e.attributes.title + '"' + selected + '>' + e.attributes.title + '</option>';
});
$('#selectTitle').html(html);
});
$('#submitTitle').on('click', function () {
var title = $('#selectTitle').val().trim();
setCurrent(title);
});
function setCurrent(name) {
var old = new AV.Query(currentData);
old.equalTo('isCurrent', true);
// old.first({
// success: function (o) {
// o.save({isCurrent: false}, {
// success: function () {
// var current = new AV.Query(currentData);
// current.equalTo('title', name);
// current.first({
// success: function (ob) {
// ob.save({isCurrent: true}, function () {
// alert('成功!');
// });
// }
// });
// }
// });
// }
// })
old.first().then(function (old) {
return old.save({isCurrent:false})
}).then(function () {
var current = new AV.Query(currentData);
current.equalTo('title', name);
return current.first();
}).then(function (cur) {
return cur.save({isCurrent: true});
}).then(function () {
alert('成功!');
});
}
})();
</script>
</body>
</html>