如何将变量传递给 Zendesk 中的应用程序

How to pass a variable to app in Zendesk

我正在试验 Zendesk 应用程序,但我在将变量/json 对象数组从我的应用程序传递到视图时遇到问题。我完成了入门教程并查看了 API,但我似乎找不到答案。

这是我的资料:

this.ajax('fetchExternalData', myURL).done(function(data) {
    this.switchTo('requester', data);
});

但是每当我尝试访问应用程序中的数据时,它都说它是未定义的(这里的数据是一个对象数组)。

I even tried something like:
    this.ajax('fetchExternalData', myURL).done(function(x) {
        this.switchTo('requester', x);
    });

其中 x 只是一些纯文本。

如果我这样做:

this.ajax('fetchExternalData', myURL).done(function(data) {
    data = data[0];
    this.switchTo('requester', data);
});

我可以通过名称访问数据中的属性(例如 {{CustomerName}}),但我仍然无法引用数据变量本身。

根据 Zendesk site :

this.switchTo('hello', {username: currentUser});

The first argument specifies the template to render, hello, which references the hello.hdbs file in the templates folder. The second argument specifies the data to pass to the template, expressed as a JavaScript object literal, {username: currentUser}. The current user's name is passed to the template to be displayed in the user interface.

所以就这样试试吧:

this.ajax('fetchExternalData', myURL).done(function(data) {
    //this.switchTo('requester', data);
    this.switchTo('requester', {data : data} );
});

希望这能解决您的问题!