2016-10-18 10 views

答えて

5

<ListPicker>itemsプロパティをページのbindingContextの配列にバインドする必要があります。ここでは基本的な例です:

<!-- 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]); 
     } 
    } 
); 
}; 
関連する問題