Spring-使用Javascript访问模型中的对象

时间:2018-07-18 13:58:55

标签: javascript spring model-view-controller model

我正在尝试使用Javascript代码访问模型中的JSON对象。 当我使用内联JavaScript时,它可以工作,但是导入JS文件时,它不起作用。

我想念什么?

控制器:

---
title: Short Paper
author:
  - name: Alice Anonymous
    email: alice@example.com
    affiliation: Some Institute of Technology
    footnote: Corresponding Author
  - name: Bob Security
    email: bob@example.com
    affiliation: Another University
address:
  - code: Some Institute of Technology
    address: Department, Street, City, State, Zip
  - code: Another University
    address: Department, Street, City, State, Zip
abstract: |
  This is the abstract.

  It consists of two paragraphs.

journal: "An awesome journal"
date: "`r Sys.Date()`"
bibliography: mybibfile.bib
output:
  bookdown::pdf_book:
    base_format: rticles::elsevier_article
---

查看:

String jsonInModel = "{'y':'Jan', 'ty':2000, 'ly':1000}";
model.addAttribute("jsonInModel", jsonInModel);

导入(底部):

<script th:inline="javascript">
    function printTest(){      
        var test = [[${jsonInModel}]]; //works
    }
</script>

JS文件:

<script src="js/lib/morris-chart/morris-init.js"></script>

我已经尝试过:

$( function () {    
  "use strict";
    var test = [[${jsonInModel}]]; //doens't work
  });

0 个答案:

没有答案