"Tabris.JS Read/Write"
Bootstrap 4.0.0 Snippet by talarie

1
2
3
4
5
6
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
const {fs, Button, TextView, TextInput, ui} = require('tabris');
/*
This works locally - but file must exist or it can't be read
*/
let file = fs.filesDir + '/hello1.txt';
// ok, this works.. > file written: /local/hello.txt
// and is located in:
// C:\Users\Rob Acer Aspire 3\AppData\Local\Packages\EclipseSource.Tabris.js2_en185yn5qwkmw\LocalState\hello.txt
console.log(file);
// button with event outside
let btnReadFile = new Button({
centerX: 0,
top: 'prev() 10',
text: 'Read File',
image: {src:'https://github.com/mrmccormack/imd-learning-tabris/blob/master/images/card.png?raw=true', scale: 1}
})
.appendTo(ui.contentView);
// event outsite create new
btnReadFile.on('select', () => {
console.log ('you pressed btnReadFile');
fs.readFile(file, 'utf-8')
.then(text => myText.text = text)
.then(text => myLabel.text = text)
// .then(text => console.log('read text from %s:', file, text))
.catch(err => console.error(err));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: