Skip to content

Instantly share code, notes, and snippets.

@segphault
Created January 18, 2015 22:22
Show Gist options
  • Select an option

  • Save segphault/f648f6a491a129acb22d to your computer and use it in GitHub Desktop.

Select an option

Save segphault/f648f6a491a129acb22d to your computer and use it in GitHub Desktop.

Revisions

  1. segphault created this gist Jan 18, 2015.
    3 changes: 3 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    var application = require("application");
    application.mainModule = "app/main";
    application.start();
    25 changes: 25 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@

    var http = require("http");

    var Observable = require("data/observable").Observable;
    var ObservableArray = require("data/observable-array").ObservableArray;

    var listStories = new ObservableArray();

    var feedUrl = "http://newsblur.com/reader/river_stories";

    exports.pageLoaded = function(args) {
    args.object.bindingContext = {
    stories: listStories
    };
    };

    exports.buttonClick = function(args) {
    http.getJSON(feedUrl).then(function(output) {
    listStories.push.apply(listStories, output.stories);
    });
    };

    exports.itemClick = function(args) {
    console.log("CLICKED ITEM:", listStories.getItem(args.index).story_title);
    };
    13 changes: 13 additions & 0 deletions main.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@

    <Page loaded="pageLoaded">
    <ScrollView>
    <StackPanel>
    <Button text="Load" click="buttonClick" />
    <ListView id="listItems" itemTap="itemClick" items="{{ stories }}">
    <ListView.itemTemplate>
    <Label id="labelItem" textWrap="true" text="{{ story_title }}" />
    </ListView.itemTemplate>
    </ListView>
    </StackPanel>
    </ScrollView>
    </Page>