【问题标题】:json data not breaking line on html listjson数据没有在html列表上换行
【发布时间】:2015-08-25 20:19:31
【问题描述】:

我正在从一个 json 文件加载数据,我计划在该文件中使用带有链接的 html 列表,我不确定问题是我如何编写 json 文件还是我如何访问文件中的数据。

根据http://jsonlint.com/ json文件是正确的

menu.json 文件

[
    {
        "opciones": {
            "oferta": [
                {
                    "tipo": "1001"
                },
                {
                    "tipo": "1002"
                },
                {
                    "tipo": "1003"
                },
                {
                    "tipo": "1004"
                }
            ]
        }
    },
    {
        "opciones": {
            "demanda": [
                {
                    "tipo": "2001"
                },
                {
                    "tipo": "2002"
                },
                {
                    "tipo": "2003"
                }
            ]
        }
    }
]

这是我尝试填充 html 列表代码的方法:

    <html ng-app="App">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
  <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
  <title>test html</title>

   <script src="json_load_menu.js"></script>   <!--script que cargar archivo json-->
  <link rel = "stylesheet"   type = "text/css"   href = "./css/style.css" />  <!--css con colores de celdas -->
  </head>

<body ng-controller="menuCtrl">

<div class="container">

    <ul >
        <li ng-repeat="menuOpcion in menu"><a href="#" >{{menuOpcion.opciones.oferta}}</a></li>
    </ul>

    <ul >
        <li ng-repeat="menuOpcion in menu"><a href="#" >{{menuOpcion.opciones.demanda}}</a></li>
    </ul>

</div>

</body>
</html> 

这是结果:

  • [{"tipo":"1001"},{"tipo":"1002"},{"tipo":"1003"},{"tipo":"1004"}]
    *

    • [{"tipo":"2001"},{"tipo":"2002"},{"tipo":"2003"}]
      *

应该做什么:

*1001
*1002
*等

*2001

*2002

如何避免这种情况?

编辑:我试过了

<ul >
        <li ng-repeat="menuOpcion in menu"><a href="#" >{{menuOpcion.opciones.oferta.tipo}}</a></li>
    </ul>

【问题讨论】:

  • 你能提供一个小提琴吗?
  • 请提问。

标签: html json angularjs


【解决方案1】:

试试

<ul>
  <li ng-repeat="menuOpcion in menu[0].opciones.oferta"><a href="#" >{{menuOpcion.tipo}}</a></li>
</ul>

<ul >
  <li ng-repeat="menuOpcion in menu[0].opciones.demanda"><a href="#" >{{menuOpcion.tipo}}</a></li>
</ul>

【讨论】:

  • 不,现在列表是空的
猜你喜欢
  • 2012-09-12
  • 1970-01-01
  • 1970-01-01
  • 2011-11-04
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多