-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepisode4-page.ts
90 lines (66 loc) · 2.24 KB
/
episode4-page.ts
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
86
87
// tslint:disable:max-line-length
import { Label } from "tns-core-modules/ui/label";
import { Observable } from "tns-core-modules/data/observable";
import { path, knownFolders, File } from "tns-core-modules/file-system";
import { Page } from "tns-core-modules/ui/page";
// >> import-http-get
import { getFile, getImage, getJSON, getString, request, HttpResponse } from "tns-core-modules/http";
// << import-http-get
import { Button } from "tns-core-modules/ui/button";
import { ImageSource } from "tns-core-modules/image-source";
export function onNavigatingTo(args) {
const page: Page = <Page>args.object;
const vm = new Observable();
vm.set("getJSONResultButton", "Show getJSON result");
vm.set("getJSONResultVisible", false);
page.bindingContext = vm;
}
export function onButtonTap(args) {
const button: Button = <Button>args.object;
const page: Page = <Page>args.object.page;
const vm = page.bindingContext;
const id: string = button.get("id");
const status: boolean = vm.get(`${id}ResultVisible`);
vm.set("name_n", " Name :");
vm.set("air_date_d", " Air date :");
vm.set("episode_e", " Episode :");
vm.set("characters_c", " Characters :");
page.bindingContext = vm;
if (!status) {
switch (id) {
case "getJSON":
getJSONExample(vm);
break;
default:
break;
}
}
switch (!status) {
case true:
vm.set(`${id}ResultButton`, `Hide ${id} result`);
break;
case false:
vm.set(`${id}ResultButton`, `Show ${id} result`);
break;
default:
break;
}
vm.set(`${id}ResultVisible`, !status);
}
export function getJSONExample(viewModel) {
// >> get-json-code-ts
getJSON("https://rickandmortyapi.com/api/episode/8").then((r: any) => {
// >> (hide)
viewModel.set("name", r.name);
viewModel.set("air_date", r.air_date);
viewModel.set("episode", r.episode);
viewModel.set("url", r.url);
// << (hide)
}, (e) => {
// >> (hide)
console.log("Error: ");
console.log(e);
// << (hide)
});
// << get-json-code-ts
}