我正在为ListView
创建一个详细信息页面。数据来自使用getJSON
的API。我正在尝试在id
请求中使用args.context
中的getJSON
。
home-item-detail-page.ts
export function onNavigatingTo(args: NavigatedData) {
const page = args.object as Page;
const project = args.context as Project;
const current = args.context as Current;
page.bindingContext = new HomeItemDetailViewModel();
}
home-item-detail-view-model.ts
export class HomeItemDetailViewModel extends Observable {
projects: ObservableArray<Item>;
current: Observable;
constructor() {
super();
// GET all projects
this.projects = new ObservableArray();
getJSON("http://localhost/api/projects").then((r: any) => {
this.projects.push(r);
}, (e) => {
});
// GET the current logged in project
this.current = new Observable();
getJSON("http://localhost/api/projects/+id").then((r: any) => {
this.current.set("name", r.name);
}, (e) => {
});
}
}
如何将context.id
分配给可在http查询getJSON("http://104.238.173.179/api/projects/+id")
中使用的变量?