我想获取在ListView中选择的项目的值(type_of_service,picture)。 servicesList.selection.type_of_service.value似乎不起作用。
var tosTable = client.getTable("TypeOfService");
var serviceTypes = new WinJS.Binding.List();
tosTable.orderBy("type_of_service")
.select("type_of_service", "picture")
.read()
.done(function (results) {
serviceTypes = new WinJS.Binding.List(results);
servicesList.winControl.itemDataSource = serviceTypes.dataSource;
});
var Service = WinJS.Class.define(
function (type_of_service, picture) {
this.type_of_service = type_of_service;
this.picture = picture;
},
{
_type_of_service: undefined,
_picture: undefined
}
);
servicesList.addEventListener("selectionchanged", function () {
var selectedService = new Service(servicesList.selection.type_of_service.value,
servicesList.selection.picture.value);
WinJS.Navigation.navigate("/pages/orgs/orgs.html");
});
});
答案 0 :(得分:0)
这行代码
servicesList.winControl.itemDataSource = serviceTypes.dataSource;
让我觉得" servicesList"是ListView DOM元素,而不是ListView本身。因此,如果您想获得选择,您应该将您的代码从servicesList.selection更改为使用servicesList。 winControl .selection。
另一件事是选择可以是多个项目,因此它不仅仅是一个数据项,而是一个ISelection接口:http://msdn.microsoft.com/en-us/library/windows/apps/hh872204.aspx
所以你必须做类似的事情:
var selection = servicesList.winControl.selection;
if(selection.count()) {
selection.getItems().then(function(items) {
// do something with the selected item
console.log(items[0].data);
}
}