用javascript寫Android和iOS naitve應用,實在炫酷。

來源:互聯網
上載者:User

標籤:

關注NativeScript有一段時間了,說好了的三月發第一個Beta版,終於發布了。

// declare the extended NativeScriptActivity functionalityvar extendsObject = {    onCreate: function(savedState){        // call the base NativeScriptActivity.onCreate method        // the "this" variable points to a NativeScriptActivity instance        this.super.onCreate(savedState);        // create a button and set it as the main content        var button = new android.widget.Button(this);        button.setText("Hello World");        this.setContentView(button);    }}// pass the extends object to create a new NativeScriptActivity instancevar mainActivity = com.tns.NativeScriptActivity.extends(extendsObject);var applicationInitObject = {    getActivity: function(intent) {        // this method is called whenever a new instance of NativeScriptActivity is about to be created        return mainActivity;    },    onCreate: function() {        // This is the first method called. Called from the android.app.Application.onCreate method.    } }// The NativeScriptRuntime exposes the app object within the global contextapp.init(applicationInitObject);

如上面代碼,用javascript創那建一個Android的Activity,是不是很炫酷!

當然也可以寫iOS native應用,這還不是最炫酷的,更炫酷的是,它還提供了一套“公用的”api,和一套可以用xml描述的ui控制項陳列庫,可以這樣定義介面,並在不同的平台下產生相應用本地控制項。

<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">  <StackLayout>    <Label text="Tap the button" cssClass="title"/>    <Button text="TAP" tap="{{ tapAction }}" />    <Label text="{{ message }}" cssClass="message" textWrap="true"/>    <Button text="test button"/>  </StackLayout></Page>

它還支援“資料繫結”,這你敢信?!

上範例:

用javascript寫Android和iOS naitve應用,實在炫酷。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.