在getJSON请求中使用NavigatedData上下文的Nativescript核心

时间:2019-05-27 21:14:31

标签: javascript typescript nativescript getjson

我正在为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")中使用的变量?

0 个答案:

没有答案