OJET网格不显示

时间:2017-10-22 14:50:58

标签: javascript java html

我是第一次尝试OJET。这是一个gradle项目。 我有一个按钮(重定向到servlet)和oj-data-grid。 在运行gradlew appRun时,一切正常但网格未显示。 这是我的代码:

的index.html

<!DOCTYPE>
<html>
<head>
    <title>My Web Page</title>
</head>
<body>
<form method="post" action="dataServlet">
    <input type="submit" value="Click"/>
</form>
<div id="oj-grid-example">
    ABCD <br/>
    <oj-data-grid id="datagrid"
                  style="width:100%;max-width:234px;height:130px"
                  aria-label="Data Grid Cell Based Grid Demo"
                  data="[[dataSource]]">
    </oj-data-grid>
    <br/>EFGH
</div>
</body>
</html>

main.js

requirejs.config({
  paths: {
    'knockout': 'libs/knockout/knockout-3.4.0',
    'jquery': 'libs/jquery/jquery-3.1.1.min',
    'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.0.min',
    'ojs': 'libs/oj/v4.0.0/min',
    'ojL10n': 'libs/oj/v4.0.0/ojL10n',
    'ojtranslations': 'libs/oj/v4.0.0/resources',
    'text': 'libs/require/text',
    'promise': 'libs/es6-promise/es6-promise.min',
    'hammerjs': 'libs/hammer/hammer-2.0.8.min',
    'signals': 'libs/js-signals/signals.min',
    'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.0.min',
    'css': 'libs/require-css/css.min',
    'customElements': 'libs/webcomponents/custom-elements.min',
    'proj4': 'libs/proj4js/dist/proj4'
  },
  shim: {
    'jquery': {
      exports: ['jQuery', '$']
    }
  },

  config: {
    ojL10n: {
      merge: {
        //'ojtranslations/nls/ojtranslations': 'resources/nls/myTranslations'
      }
    },
    text: {
      useXhr: function (url, protocol, hostname, port) {
        return true;
      }
    }
  }
});


require(['ojs/ojcore', 'knockout', 'jquery', 'ojs/ojknockout', 'promise',
'ojs/ojdatagrid', 'ojs/ojarraydatagriddatasource'],
function(oj, ko, $)
{
    function viewModel()
    {
        var self = this;
        var dataArray = [
            ['1', '2', '3'],
            ['4', '5', '6'],
            ['7', '8', '9']
        ];
        self.dataSource = new oj.ArrayDataGridDataSource(dataArray);
    }

    $(
        function()
        {
            ko.applyBindings(new viewModel(), document.getElementById('datagrid'));
        }
    );
});

的build.gradle

plugins {
    id 'java'
    id 'war'
    id 'org.akhikhl.gretty' version '1.4.2'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

输出

Click [Imagine this as a clickable button. This part of the code works]
ABCD 

EFGH

如输出所示,数据网格未显示。

gradle.build需要特殊配置吗?

2 个答案:

答案 0 :(得分:1)

您是否添加了脚本标记以进行初始化?试试这个: -

<link href="css/libs/oj/v4.0.0/alta/oj-alta-min.css"
          rel="stylesheet"
          type="text/css"/>
<script data-main="js/main"
            src="js/libs/require/require.js">
</script>

答案 1 :(得分:0)

我的错误。

忘记添加脚本标签以进行初始化:

<link href="css/libs/oj/v4.0.0/alta/oj-alta-min.css"
          rel="stylesheet"
          type="text/css"/>
<script data-main="js/main"
            src="js/libs/require/require.js">
</script>
傻傻的我:) 无需其他配置。