-
Notifications
You must be signed in to change notification settings - Fork 68
/
should_change_binding_context_using_with.html
59 lines (45 loc) · 1.53 KB
/
should_change_binding_context_using_with.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
<!DOCTYPE html>
<html>
<head>
<title>Should change binding context using with</title>
<script type="text/javascript" src="../lib/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../lib/underscore-min.js"></script>
<script type="text/javascript" src="../lib/knockout-2.1.0.js"></script>
<script type="text/javascript" src="../pager.js"></script>
<link rel="stylesheet" href="../lib/qunit.css"/>
</head>
<body>
<div id="qunit"></div>
<div data-bind="page: {id: 'user', 'with': user}">
<!-- Here name is user.name -->
<div id="name" data-bind="text: name"></div>
</div>
<div data-bind="page: {id: 'admin', 'with': admin}">
<!-- Here name is user.name -->
<div id="error" data-bind="text: error"></div>
</div>
<script type="text/javascript">
var viewModel = {
user:{
name:ko.observable("Arne")
},
admin:{
error:"404"
}
};
pager.extendWithPage(viewModel);
ko.applyBindings(viewModel);
pager.start();
</script>
<script type="text/javascript" src="../lib/qunit-until.js"></script>
<script type="text/javascript" src="../lib/qunit.js"></script>
<script type="text/javascript">
test("Should change binding context using with", function () {
equal($('#name').text(), "Arne", "the name should be Arne");
equal($('#error').text(), "404", "the error should be 404");
viewModel.user.name("Sofia");
equal($('#name').text(), "Sofia", "the name should be Sofia now");
});
</script>
</body>
</html>