Nativescript 下拉插件只显示 Object 对象而不是值
Nativescript drop down plugin display only Object object instead of value
我正在尝试在下拉列表中显示对象值,并希望在 select 任何值时获取整个对象值。我该如何设置?
我正在尝试使用“.”访问要显示的对象值。运算符如下
<dd:DropDown items="{{ raw_material_list.productName }}" selectedIndex="{{ raw_material_index }}" opened="dropDownOpened" closed="dropDownClosed" selectedIndexChanged="dropDownSelectedIndexChanged" class="dropDownStyle" />
我传递的数据如下
raw_material_list = [
{
"id": "44",
"created_date": "2019-04-19 12:01:13",
"activeFlag": "true",
"productType": "purchase",
"productName": "suraksha",
},
{
"id": "43",
"created_date": "2019-04-19 11:59:59",
"activeFlag": "true",
"productType": "purchase",
"productName": "vajra",
}
];
我需要得到与我提到的完全一样的结果,欢迎任何帮助。
我更新了你的游乐场here
在 drop-down-common.js
中将 display
更改为 productName
ValueList.prototype.getDisplay = function (index) {
if (types.isNullOrUndefined(index)) {
return null;
}
if (index < 0 || index >= this.length) {
return "";
}
return this._array[index].productName;
};
P.S。您必须对对象使用 ValueList
。
上面的答案是正确的,但是对于这个问题,非常简单直接的解决方案是
var nativescript_drop_down_1 = require("../nativescript-drop-down") //Plugin
1> modify the array list like below
raw_material_list = new nativescript_drop_down_1.ValueList([
{
"id": "44",
"created_date": "2019-04-19 12:01:13",
"activeFlag": "true",
"productType": "purchase",
"productName": "suraksha",
},
{
"id": "43",
"created_date": "2019-04-19 11:59:59",
"activeFlag": "true",
"productType": "purchase",
"productName": "vajra",
}
]);
2>to access data
let obj = viewModel.get("raw_material_list")._array[viewModel.get("raw_material_index")];
console.log("----obj-----");
console.log(obj);
我正在尝试在下拉列表中显示对象值,并希望在 select 任何值时获取整个对象值。我该如何设置?
我正在尝试使用“.”访问要显示的对象值。运算符如下
<dd:DropDown items="{{ raw_material_list.productName }}" selectedIndex="{{ raw_material_index }}" opened="dropDownOpened" closed="dropDownClosed" selectedIndexChanged="dropDownSelectedIndexChanged" class="dropDownStyle" />
我传递的数据如下
raw_material_list = [
{
"id": "44",
"created_date": "2019-04-19 12:01:13",
"activeFlag": "true",
"productType": "purchase",
"productName": "suraksha",
},
{
"id": "43",
"created_date": "2019-04-19 11:59:59",
"activeFlag": "true",
"productType": "purchase",
"productName": "vajra",
}
];
我需要得到与我提到的完全一样的结果,欢迎任何帮助。
我更新了你的游乐场here
在 drop-down-common.js
中将display
更改为 productName
ValueList.prototype.getDisplay = function (index) {
if (types.isNullOrUndefined(index)) {
return null;
}
if (index < 0 || index >= this.length) {
return "";
}
return this._array[index].productName;
};
P.S。您必须对对象使用 ValueList
。
上面的答案是正确的,但是对于这个问题,非常简单直接的解决方案是
var nativescript_drop_down_1 = require("../nativescript-drop-down") //Plugin
1> modify the array list like below
raw_material_list = new nativescript_drop_down_1.ValueList([
{
"id": "44",
"created_date": "2019-04-19 12:01:13",
"activeFlag": "true",
"productType": "purchase",
"productName": "suraksha",
},
{
"id": "43",
"created_date": "2019-04-19 11:59:59",
"activeFlag": "true",
"productType": "purchase",
"productName": "vajra",
}
]);
2>to access data
let obj = viewModel.get("raw_material_list")._array[viewModel.get("raw_material_index")];
console.log("----obj-----");
console.log(obj);