내 Ajax 호출에서 결과가 표시되지만 채워진 select
요소는 재질 선택시 브라우저 선택 기본값에서만 렌더링됩니다. 나는 이미 안에 $.each
, $.append
안에 모두 기능을 렌더링하고 다양한 기능을 시도했지만 결과는 없었지만 성공했다.재료 디자인에서 선택하지 않음 - 예기치 않은 토큰`< '
템플릿 측면.
<div class="input-field col s12">
<select id="getUnit" ></select>
<label>Units</label>
</div>
아약스 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 레이블 만 표시합니다.
편집 :
어디에서 선택 하시겠습니까? $ unit입니까? – epascarello
'$ .each'가 끝나면'$ unit.material_select();'를 실행하십시오. 그렇게해야합니다. – trincot
@epascarello yesss – Gabriel