【发布时间】:2015-10-25 15:32:51
【问题描述】:
我正在使用 Semantic UI 2.0 并尝试使用从其 API 返回的数据在我的下拉列表中构建选项。
对于下拉列表本身,我使用的代码与 Semantic UI 文档中显示的 this 代码几乎相同:
<div class="ui search selection dropdown select-city">
<input type="hidden" name="city">
<i class="dropdown icon"></i>
<div class="default text">Select City</div>
</div>
我有一个返回 json 格式城市的服务,然后 Semantic UI 在控制台中显示所有 261 个城市的结果都成功:
"Using specified url" ["/cities/"] 1648
"Querying URL" ["/cities/"] 0
"Sending request" [undefined, "get"] 0
"Successful API Response" [Object { success=true, results=[261]}]
/cities 端点返回一个 json,格式如下:
{"success":true,"results":[{"description":"Opole","data-value":1},{"description":"Wrocław","data-value":2},{"description":"Warszawa","data-value":3},{"description":"Budapest","data-value":4},{"description":"Köln","data-value":5}, ...]}
Semantic UI 好像没有直接理解 json 的格式。
我尝试了许多格式的 json 属性,甚至尝试对 html 进行一些更改。例如,尝试在 select 底部添加一个空的<div class="menu">,希望 Semantic UI 将其填充,例如:
<div class="ui search selection dropdown select-city">
<input type="hidden" name="city">
<i class="dropdown icon"></i>
<div class="default text">Select City</div>
<div class="menu"></div>
</div>
我正在尝试将属性的格式与example 中的格式相匹配,例如,使用“data-value”属性。
但它也不起作用,我在源代码中看到了 Semantic UI checks for that,所以它没有任何区别。最后,我的问题仍然存在,下拉选择中没有插入任何项目。
【问题讨论】:
-
您究竟是如何获取这些数据的?能发下相关代码吗?
-
抱歉,我如何获取这些数据的响应时间过长。以前我在语义 ui 中使用默认的 .api 函数。由于它不起作用,现在我正在使用ajax调用并自己填写菜单,而不是使用semantic-ui api的自动过程。我将尝试重做我之前使用的代码并更新问题。
标签: javascript html json drop-down-menu semantic-ui