私のAjax呼び出しで結果が得られますが、埋め込まれたselect
要素は選択されたブラウザのデフォルトでのみマテリアルスタイルでレンダリングされません。私はすでにに$.each
、$.append
の両方の内部と何も結果を出さないで、さまざまな形式のレンダリング機能を試しました。材料デザインでレンダリングしません - 予期しないトークン `<'
テンプレート側。
<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