我在我的Ajax调用中获取了结果,但填充的select
元素未以材质样式呈现,仅在选择浏览器默认情况下呈现。我已经尝试过在$.each
,$.append
以及功能成功但没有结果的$('select').material_select();
中呈现我的功能的各种形式。在材质设计中选择未呈现 - 意外标记`<`
模板面。
<div class="input-field col s12">
<select id="getUnit" ></select>
<label>Units</label>
</div>
Ajax Jquery Get。
$(function() {
//request the JSON data and parse into the select element
$.ajax({
type: "GET",
url: '/product/unit-measurement-search',
success: function (unitMeasurement) {
//get a reference to the select element
$unit = $('#getUnit');
//clear the current content of the select
$unit.html('');
//iterate over the data and append a select option
$.each(unitMeasurement, function (info, unitSearch) {
$unit.append('<option id="' + unitSearch.descriptionUnitMeasurement + '">' + unitSearch.descriptionUnitMeasurement + '</option>');
});
}
});
});
后端处理请求json。
router.get('/product/unit-measurement-search', function (req, res) {
connection.query('SELECT
acronymUnitMeasurement,descriptionUnitMeasurement FROM unit_measurement',
function (err, unitMeasurement, fields) {
if (err) {
throw err;
}
res.send(unitMeasurement);
}
);
});
在前端模板中返回时只显示select的标签。
编辑:
这是我的控制台输出:
你在哪里选择选择?是$单位吗? – epascarello
'$ .each'完成后,执行'$ unit.material_select();'。这应该做到这一点。 – trincot
@epascarello yesss – Gabriel