当我使用JSON文件作为源时,SAPUI5 oModel.getJSON()无法正常工作 [英] SAPUI5 oModel.getJSON() isn't working when I use a JSON file as origin

查看:140
本文介绍了当我使用JSON文件作为源时,SAPUI5 oModel.getJSON()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JSON文件创建了模型.

I created my Model using a JSON file.

var oModel = new sap.ui.model.json.JSONModel( jsonFileUrl ); //JSON from file

它起作用了,并且根据需要填充了该元素. 但是之后,当我尝试使用oModel.getJSON()来获取JSON数据时,它不起作用.

It worked and the element was populated as I wanted. But after this, when I tried to use oModel.getJSON() to get the JSON data it didn't work.

如果我使用与文件内容相同的变量,那么它将起作用!

If I use an variable with the same content as the file, it works!

您可以检查我创建的完整测试: https://googledrive.com/host/0B2gJUv6a_V1dYnNSV0ZsTFhxaz/index.html

You can check the full test that I created: https://googledrive.com/host/0B2gJUv6a_V1dYnNSV0ZsTFhxazg/index.html

有没有人可以帮助我了解地球上正在发生的事情?

Is there anybody to help me to understand what on Earth is happening here?

推荐答案

这是因为在您尝试在此处发出JSON时:

It's because at the time you try to emit the JSON here:

$("#jsonFile").append(oModelFile.getJSON());

检索文件的实际ajax请求尚未完成,因此当时未填充JSON模型.

the actual ajax request to retrieve the file hasn't completed, and so the JSON model isn't filled at that time.

将其包装在像这样的requestCompleted事件的处理程序中,它将起作用:

Wrap this in a handler for the requestCompleted event like this and it will work:

oModelFile.attachRequestCompleted(function() {
  $("#jsonFile").append(oModelFile.getJSON());
});

这篇关于当我使用JSON文件作为源时,SAPUI5 oModel.getJSON()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆