cancel
Showing results for 
Search instead for 
Did you mean: 

sap.ui.define: JSONModel is not defined(…)

draschke
Active Contributor
0 Kudos

Hi,

whats wrong with my path?

UIComponent and Device are fine, but JSONModel  is not defined.

Get the error: Uncaught ReferenceError: JSONModel is not defined(…)

Could somebody help me?

Thanks

Accepted Solutions (0)

Answers (4)

Answers (4)

draschke
Active Contributor
0 Kudos

Thank you all for great help!

After I initialized JSONModel with this coding, it was defined.

            var rootPath = jQuery.sap.getModulePath("ui5bp");

            var oModel = new JSONModel(jQuery.sap.getModulePath("ui5bp", "/model/menu.json"));

            this.getView().setModel(oModel);

I thought the JSONModel is automatically initialized with the entries inside of the manifest(ab Version 1.30) and I don't need the whole syntax.

Unfortunately I didn't find a sample for the new syntax (inside of manifest), if I want to load a local json file.

draschke
Active Contributor
0 Kudos

Could it have something to do with the manifest.json file?

former_member182372
Active Contributor
0 Kudos

try to remove it 😉

former_member182372
Active Contributor
0 Kudos

post it btw

seVladimirs
Active Contributor
0 Kudos

Well, source code you have posted is working as a charm - see demo here - http://plnkr.co/edit/uc9kCHEHMtRwcTcVTuCm?p=preview

former_member182372
Active Contributor
0 Kudos

if you remove it from line 5 and line 3 and use full path like

var oJSONModel = new sap.ui.model.json.JSONModel();

does it work?

draschke
Active Contributor
0 Kudos

yes, this works!

former_member182372
Active Contributor
0 Kudos

post the old code and show where exactly is the exception

former_member182372
Active Contributor
0 Kudos

SAPUI5 Explored

sap.ui.define([
'jquery.sap.global',
'./Formatter',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
], function(jQuery, Formatter, Controller, JSONModel) {
"use strict";

var TableController = Controller.extend("sap.m.sample.Table.Table", {

onInit
: function () {
// set explored app's demo model on this sample
var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/products.json"));
this.getView().setModel(oModel);
}
});


return TableController;

});



same as you have....hm..

draschke
Active Contributor
0 Kudos
former_member182372
Active Contributor
0 Kudos

turn on debug.. expand that last error, it will print the stack trace.

draschke
Active Contributor
0 Kudos
draschke
Active Contributor
0 Kudos

Is this what you want?

In my opinion, JSONModel should be defined with the init. Should it?

former_member183518
Active Participant
0 Kudos

Can you post the code where you're trying to use the JSONModel ?

former_member182372
Active Contributor
0 Kudos

line #5

former_member183518
Active Participant
0 Kudos

But line#5 wouldn't throw a reference error even if it's undefined.

former_member182372
Active Contributor
0 Kudos

true

draschke
Active Contributor
0 Kudos

sap.ui.define([

    "sap/ui/core/UIComponent",

    "sap/ui/model/json/JSONModel",

    "sap/ui/Device"

], function(UIComponent, JSONModel, Device) {

    "use strict";

    return UIComponent.extend("ui5bp.Component", {

        metadata: {

            manifest: "json"

        },

        /**

         * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.

         * @public

         * @override

         */

        init: function() {

            // call the base component's init function

            UIComponent.prototype.init.apply(this, arguments);

        }

    });

});

draschke
Active Contributor
0 Kudos

<!DOCTYPE html>

<html>

<head>

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <meta charset="UTF-8">

    <title>UI5 Boilerplate Fiori</title>

    <!-- UI5 Bootstrap with OpenUI5 -->

    <script

  id="sap-ui-bootstrap"

  src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"

  data-sap-ui-theme="sap_bluecrystal"

  data-sap-ui-libs="sap.m,sap.ui.commons,sap.ui.table,sap.ui.ux3"

  data-sap-ui-bindingSyntax="complex"

  data-sap-ui-compatVersion="edge"

  data-sap-ui-preload="async"

  data-sap-ui-resourceroots='{

  "ui5bp": "./"

  }'>

  </script>

  <script>

  sap.ui.getCore().attachInit(function () {

  new sap.m.Shell({

  app: new sap.ui.core.ComponentContainer({

  name: "ui5bp",

  height: "100%"

  })

  }).placeAt("content");

  });

  </script>

</head>

<body class="sapUiBody" id="content">

</body>

</html>