我想渲染<select>输入的HTML5属性,以便我可以使用jquery图像选择器进行反应.我的代码是:
var Book = React.createClass({
render: function() {
return (
<option data-img-src="{this.props.imageUrl}" value="1">{this.props.title}</option>
Run Code Online (Sandbox Code Playgroud)
问题是,即使{this.props.imageUrl}正确地传递为a prop,它也不会在HTML中呈现 - 它只是呈现为{this.props.imageUrl}.如何使变量正确传递到HTML中?
我正在使用 <datalist>
<datalist id="items"></datalist>
Run Code Online (Sandbox Code Playgroud)
并使用AJAX填充列表
function callServer (input) {
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
//return the JSON object
console.log(xmlhttp.responseText);
var arr = JSON.parse(xmlhttp.responseText);
var parentDiv = document.getElementById('items');
parentDiv.innerHTML = "";
//fill the options in the document
for(var x = 0; x < arr.length; x++) {
var option = document.createElement('option');
option.value = arr[x][0];
option.innerHTML = arr[x][1];
//add each autocomplete option to the 'list'
option.addEventListener("click", function() {
console.log("Test");
});
parentDiv.appendChild(option);
};
} …Run Code Online (Sandbox Code Playgroud)