What is NativeScript syntax for list-picker?

nativescript

Solution

What you’ll need to do is bind a `<ListPicker>`’s `items` property to an array on your page’s `bindingContext`. Here’s a basic example:

<!-- main-page.xml -->
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded">
  <StackLayout>
    <ListPicker
      items="{{ pokemon }}"
      id="pokemonPicker"
    ></ListPicker>
  </StackLayout>
</Page>
// main-page.js
var Observable = require("data/observable").Observable;

var pageData = new Observable({
  pokemon: ["Bulbasaur", "Charmander", "Squirtle"]
});

exports.pageLoaded = function(args) {
  var page = args.object;
  page.bindingContext = pageData;

  page.getViewById("pokemonPicker").addEventListener(
    Observable.propertyChangeEvent, function(e) {
      if (e.propertyName == "selectedIndex") {
        console.log("You selected: " + pageData.pokemon[e.value]);
      }
    }
  );
};

Problem

I have not been able to find a working example of NS+JS for list-picker, non of the examples in the docs have XML examples. Can anyone help?

Original source