javascript - w3.js 中的信息阅读困难
问题描述
在 w3.js 中
{
"customers":[
{"CustomerName" : "Alfreds Futterkiste","City" : "Berlin","Country" : "Germany"},
{"CustomerName" : "Berglunds snabbköp","City" : "Luleå","Country" : "Sweden"},
]}
<select id="id01">
<option w3-repeat="customers">{{CustomerName}}</option>
</select>
<script>
w3.getHttpObject("customers.js", myFunction);
function myFunction(myObject) {
w3.displayObject("id01", myObject);
}
</script>
但我的对象没有任何名称,例如(客户),并且是:
[{"id":12,"name":"hamwrew"},{"id":13,"name":"mamad2"}]
如何显示我的对象?在 html 或 jsp 页面中
解决方案
你没有一个对象,而是一个数组,所以首先从你的数组创建一个对象:
var dataArray = [{"id":12,"name":"hamwrew"},{"id":13,"name":"mamad2"}];
var nameList = { names: dataArray };
所以:
<select id="id01">
<option w3-repeat="names" value={{id}}>{{name}}</option>
</select>
<script>
w3.getHttpObject("customers.js", myFunction);
function myFunction(myArray) {
var nameList = { names: myArray};
w3.displayObject("id01", nameList);
}
</script>
推荐阅读
- azure-active-directory - 在 Azure OIDC 注销后,应该将什么内容安全策略标头值重定向回应用程序
- java - 如何在没有 PG 服务器和 Web 控制台的情况下启动 H2 数据库命令行?
- php - 基于帖子术语的 Wordpress 搜索
- django - 如何在 docker 中设置 celery beat?
- python - Python中if语句的问题
- linked-list - 我可以只使用 ALLOCATABLE 变量而不是指针在 Fortran 中创建链接列表吗?
- python - Python 在一行中查找单词并将其附加到一个新的文本文件中
- r - 从向量制作对称矩阵
- django - 如何使用 Django-quill-editor 从数据库中以 Quill 格式提取数据并提供给 Quill 表单
- python - Discord Python Bot 播放音乐 - url 是缺少的必需参数