如何通过SC.Request.get Url获取放置在myapp / app / myapp / jsons /中的静态文件(.json)

时间:2011-07-05 12:36:42

标签: sproutcore

我的萌芽核心应用名称是myapp。我的目录结构是myapp / apps / myapp /。 我在myapp / apps / myapp /中创建了一个名为jsons的目录,并放置了一个名为emp.json的文件,我希望使用SC.Request.getUrl通过ajax获取此文件。我尝试了以下但没有奏效。我想知道要联系这个文件的网址。

SC.Request.getUrl('/myapp/apps/myapp/resources/emp.json').notify(this, this.didFetchContacts)
.send();

SC.Request.getUrl('/myapp/resources/emp.json').notify(this, this.didFetchContacts)
.send();

由于

1 个答案:

答案 0 :(得分:0)

好的,你需要使用static_url。因此,如果emp.json在您的资源目录中,您可以调用它:

    SC.Request.getUrl(static_url('emp.json')).notify(this, this.didFetchContacts)
              .send();

注意:这不是一个javascript函数。编译器会将其替换为构建应用程序中文件的位置

相关问题