每个Listview项都有一个堆栈布局,应在点击该项目时打开该布局。
我已经尝试用homeViewModel.set("isVisible", !homeViewModel.get("showDetails"))
将“ showDetails”设置为true / false,但这没用。
XML:
<ActionBar title="Home" class="action-bar">
</ActionBar>
<ListView itemTap="onItemTap" items="{{ items }}">
<ListView.itemTemplate>
<StackLayout>
<Label text="{{ name }}" tap="onItemTap2" />
<StackLayout visibility="{{ showDetails ? 'visible' : 'collapsed' }}">
<TextField hint="Stunden" />
<TextField hint="Pause" />
</StackLayout>
</StackLayout>
</ListView.itemTemplate>
</ListView>
型号:
onst HomeViewModel = require("./home-view-model");
var homeViewModel = new HomeViewModel();
exports.loaded = function(args){
var page = args.object;
page.bindingContext = homeViewModel;
}
exports.onItemTap = function () {
homeViewModel.set("showDetails", !homeViewModel.get("showDetails"))
}
ViewModel:
var observableModule = require("tns-core-modules/data/observable");
const fromObject = require("tns-core-modules/data/observable").fromObject;
var observable = require("data/observable");
var observableArray = require("data/observable-array");
function HomeViewModel() {
var pageData = new observable.Observable();
var items = new observableArray.ObservableArray([]);
items.push({ name: "Januar" });
items.push({ name: "Februar" });
items.push({ name: "März" });
items.push({ name: "April" });
items.push({ name: "Mai" });
items.push({ name: "Juni" });
items.push({ name: "Juli" });
items.push({ name: "August" });
items.push({ name: "September" });
items.push({ name: "Oktober" });
items.push({ name: "November" });
items.push({ name: "Dezember" });
pageData.set("showDetails", true);
pageData.set("items", items);
return pageData;
}
module.exports = HomeViewModel;
每当我在列表视图中点击一个项目时,我都希望通过将“ showDetails”设置为true或false来打开和关闭它。