PeterStaev / NativeScript-Drop-Down

A NativeScript DropDown widget.
Apache License 2.0
105 stars 65 forks source link

List displays [object, object] #235

Closed Whip closed 4 years ago

Whip commented 4 years ago

Similar to #30 I'm getting [object, object] in the dropdown list.

CLI: 6.4.1 Cross-platform modules: 6.4.2 Runtime(s): Android 6.4.1 Nativescript Dropdown: 5.0.4

var subTopicsData = new ObservableArray([{value: 'AA', display: 'AAAA'}, {value: 'BB', display: 'BBBB'}]);
exports.onLoaded = function(args){
    page = args.object;

    viewModel = Observable({
        subTopicsData: subTopicsData,
        subTopic: null
    });
    page.bindingContext = viewModel;
}

<dd:DropDown items="{{ subTopicsData }}" selectedIndex="{{ subTopic }}" background="#333" />

I also tried using ValueList but I get an error ValueList is not a constructor

const ValueList = require('nativescript-drop-down');
var subTopicsData = new ValueList([{value: 'AA', display: 'AAAA'}, {value: 'BB', display: 'BBBB'}])
PeterStaev commented 4 years ago

Hey @VeeK727, if you use ObservableArray then it should be of simple types (for example string). The only other way is to use ValueList.

The problem is that you are not using ValueList as per the readme/demos in this repo. Please read again how you should use and import the ValueList class.

Whip commented 4 years ago

Hi @PeterStaev I saw the demo but I don't know TS very well. Could you point me to a JS example? I believe I'm not loading it correctly.

Whip commented 4 years ago

Nevermind I got it. Here's how

const ValueList = require('nativescript-drop-down').ValueList;
var subTopicsData = new ValueList([{value: 'AA', display: 'AAAA'}, {value: 'BB', display: 'BBBB'}])

Thanks