SAPUI5:JSONModel不是构造函数

时间:2017-03-16 10:34:52

标签: sapui5

我有一个包含2个视图的SAPUI5应用程序。当我尝试使用路由器从第一个视图导航到第二个视图时,它会抛出此错误:

“未捕获的TypeError:JSONModel不是构造函数(...)”

问题是我必须使用JSON的内容来填充表格,并且这个错误仍然是空的

在类似的情况/应用程序中,我的代码运行没有问题,所以如果有人可以在有错误的情况下阅读我的代码,我会很高兴...

Main.view.xml

<mvc:View controllerName="App.controller.Main" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m">
<App>
    <pages>
        <Page>
            <content>
                <Table id="paramTable" items="{/callbackData}" width="auto" class="sapUiResponsiveMargin">
                    <columns>
                        <Column>
                            <Label text="Parameter"></Label>
                        </Column>
                        <Column width="10%">
                            <Label text="CurrentVal"></Label>
                        </Column>
                        <Column width="10%">
                            <Label text="TargetVal"></Label>
                        </Column>
                        <Column width="30%">
                            <Label text="Description"></Label>
                        </Column>
                    </columns>
                    <items>
                        <ColumnListItem>
                            <cells>
                                <ObjectIdentifier title="{key}"></ObjectIdentifier>
                            </cells>
                            <Text text="{currentVal}"></Text>
                            <Text text="{operator} {targetVal}"></Text>
                        </ColumnListItem>
                    </items>
                </Table>
            </content>
        </Page>
    </pages>
</App>

Main.controller.js

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

return Controller.extend("App.controller.Main", {

    onInit : function() {

        this.getView().setModel(new JSONModel({
            callbackData: []
        }));

    },

    setTableData : function() {
        var here = this;
        $.ajax({
            url : '../../test.xsjs',
            type : "GET",
            success : function(data) {
                here.getView().getModel().setProperty("/callbackData", data);
            }
        });
    }
});
});

提前致谢!!!

1 个答案:

答案 0 :(得分:0)

var oModel = new JSONModel({
                  callbackData: []
                 });

this.getView().setModel(oModel);