项目作者: 247521776

项目描述 :
使用tabrisjs搭建app
高级语言: JavaScript
项目地址: git://github.com/247521776/account-book.git
创建时间: 2017-11-06T09:05:47Z
项目社区:https://github.com/247521776/account-book

开源协议:

下载


account-book

Run

In the project directory, run the Tabris CLI command:

  1. tabris serve

This will start a JavaScript app code server at a free port and print its URL to the console.

The JavaScript app code can be side-loaded in the developer app if the default config.xml was not changed. Otherwise, the JavaScript app code must be side-loaded in a debug build of this app.

Build

The app can be built using the online build service at tabrisjs.com or locally using Tabris.js CLI.

See Building a Tabris.js App for more information.

tabris.js的使用

初步搭建

必备条件

  • node版本 >= 6.0
  • 全局安装tabris-cli
  • 手机调试app:Tabris.js 2

git上创建一个空项目,随后克隆下来git clone xxxxx.git,之后执行tabris init初始化项目,最后执行tabris serve,项目启动。
中文文档
官网文档

使用

绑定元素

  1. const { TextView, ui, TextInput } = require('tabris');
  2. new TextView({
  3. id: 'test',
  4. left: '10%',
  5. top,
  6. text: text,
  7. font: '20px'
  8. })
  9. .appendTo(ui.contentView);
  10. new TextInput({
  11. baseline: '#test',
  12. id: 'username',
  13. left: '35%',
  14. right: '20%',
  15. height: 35
  16. })
  17. .appendTo(ui.contentView);

弹层

  1. const { AlertDialog } = require('tabris');
  2. new AlertDialog({
  3. buttons: {
  4. cancel: '取消'
  5. },
  6. message: 'test'
  7. })
  8. .open();

想要获取参数

  1. const {ui, TextInput, Page, NavigationView} = require('tabris');
  2. let navigationView = new NavigationView({
  3. left: 0, top: 0, right: 0, bottom: 0
  4. })
  5. .appendTo(ui.contentView);
  6. const page = new Page({
  7. title: 'test'
  8. })
  9. .appendTo(navigationView);
  10. new TextInput({
  11. id: 'test',
  12. left: '35%',
  13. right: '20%',
  14. height: 35,
  15. text: 'test'
  16. })
  17. .appendTo(page);
  18. // 获取input框信息
  19. page.find('#test').get('text');

http请求

  1. const data = JSON.stringify({});
  2. let myHeaders = new Headers();
  3. myHeaders.append('Content-Type', 'application/json; charset=utf-8');
  4. myHeaders.append('Content-Length', data.length);
  5. const request = new Request('http://xxxx', {
  6. method: 'POST',
  7. mode: 'no-cors',
  8. body:data,
  9. headers:myHeaders
  10. });
  11. fetch(request)
  12. .then((response) => response.json())
  13. .then((result) => {
  14. console.log(result);
  15. })
  16. .catch((err) => {
  17. console.error(err);
  18. });

page跳到page,跳回

  1. // 当前页调用,即可跳回上一页
  2. navigationView.pages().dispose();
  3. 或者
  4. page.dispose();
  5. 在同一个navigationView中的可自带跳回按钮
  6. const {Button, NavigationView, Page, ui} = require('tabris');
  7. let pageCount = 0;
  8. let navigationView = new NavigationView({
  9. left: 0, top: 0, right: 0, bottom: 0
  10. }).appendTo(ui.contentView);
  11. createPage();
  12. function createPage(title) {
  13. let page = new Page({
  14. title: title || 'Initial Page'
  15. }).appendTo(navigationView);
  16. new Button({
  17. left: 16, top: 16, right: 16,
  18. text: 'Create another page'
  19. }).on('select', () => createPage('Page ' + (++pageCount)))
  20. .appendTo(page);
  21. new Button({
  22. left: 16, top: 'prev() 16', right: 16,
  23. text: 'Go back'
  24. }).on('select', () => page.dispose())
  25. .appendTo(page);
  26. new Button({
  27. left: 16, top: 'prev() 16', right: 16,
  28. text: 'Go to initial page'
  29. }).on('select', () => {
  30. navigationView.pages().dispose();
  31. createPage();
  32. }).appendTo(page);
  33. return page;
  34. }