这个代码出了什么问题?错误丢失”)&”;
What is wrong with this code? Error missing ")"
除了这行之外,代码仍在正常工作
$('#ReplenishItem').append('<tr><td><input type="hidden" name="" value="' + data[0].itemCode + '"/>'n'<input type="text" value="' + data[0].productName + '"/> 'n'</td><td>'n'<select name="size">'
for (var y in data) {
''<option value="' + data[y].size + '">' + data[y].size + ''</option>'
}
''</select>'n'</td>'n'</tr>');
}
我试着删除上面的一行,它有效,也试着在没有循环的情况下追加,它有效。我不需要正确的方法来做这件事,但希望上面的代码可以工作
var x = true;
function autoCompleteWarehouseInventory() {
$("#productName").devbridgeAutocomplete({
serviceUrl: 'searchWarehouseInv',
type: 'POST',
showNoSuggestionNotice: true,
noSuggestionNotice: 'No Exsiting Product',
onSelect: function (event, ui) {
var productName = document.getElementById('productName').value;
$.ajax({
type: 'POST',
url: 'SetWarehouseInvServlet',
dataType: 'json',
data: {
productName: productName
},
success: function (data) {
if (x) {
$('#ReplenishItem').append('<tr>'n'
<th>Product Name</th><th>Color</th><th>Size</th><th>Quantity</th></tr>');
x = false;
};
$('#ReplenishItem').append('<tr><td><input type="hidden" name="" value="' + data[0].itemCode + '"/>'n'<input type="text" value="' + data[0].productName + '"/> 'n'</td><td>'n'<select name="size">'
for (var y in data) {
''<option value="' + data[y].size + '">' + data[y].size + ''</option>'
}
''</select>'n'</td>'n'</tr>')
}
});
}
});
}
不能让for...in
循环与这样的字符串串联在一起。
可以使用Array.prototype.map
和Array.prototype.join
来格式化data
中的<option>
元素字符串。
例如:
$('#ReplenishItem').append('<tr><td><input type="hidden" name="" value="'+ data[0].itemCode +'"/>'n'
<input type="text" value="'+ data[0].productName +'"/> 'n'
<td><td>'n'
<select name="size">'
+ data.map(function(opt) { return '<option value="'+ opt.size +'">'+ opt.size + '</option>' }).join("")
+ '</select>'n'
</td>'n'
</tr>');
您应该尝试使用一个将大括号和圆括号配对的编辑器。:)
试试这个:
var x =true;
function autoCompleteWarehouseInventory() {
$("#productName").devbridgeAutocomplete({
serviceUrl: 'searchWarehouseInv',
type: 'POST',
showNoSuggestionNotice: true,
noSuggestionNotice: 'No Exsiting Product',
onSelect: function (event, ui) {
var productName = document.getElementById('productName').value;
$.ajax({
type: 'POST',
url: 'SetWarehouseInvServlet',
dataType: 'json',
data: {
productName: productName
},
success: function (data) {
if(x){
$('#ReplenishItem').append('<tr>'n<th>Product Name</th><th>Color</th><th>Size</th><th>Quantity</th></tr>');
x = false;
}
var options = '';
for(var y in data){
options += '<option value="'+ data[y].size +'">'+ data[y].size + '</option>';
}
$('#ReplenishItem').append(
'<tr>'+
'<td>'+
'<input type="hidden" name="" value="'+ data[0].itemCode +'"/>'+
'<input type="text" value="'+ data[0].productName +'"/>'+
'</td>'+
'<td>'+
'<select name="size">'+
options
'</select>'+
'</td>'+
'</tr>');
}
});
}
});
}
相关文章:
- 咕噜声.js无法读取文件(错误代码:EISDIR)
- 科尔多瓦指南针 API 给出错误代码 3
- 如何在使用JavascriptCallbackBehavior时引发带有HTTP错误代码的WebFaultExcepti
- 解析错误代码 121
- Ajax get jsonp给出错误代码500“;请求被阻止”;来自MVC应用程序
- ionic http获取到本地文件会给出http错误代码0
- Imacros/jQuery TypeError:无法访问死对象,第 816 行(错误代码:-991)
- 电话差距/网络数据库错误代码说明
- NaN 错误代码有什么问题
- 异常:“远程主机关闭了连接.错误代码为 0x80070057”
- 咕噜声/巴别塔错误:无法写入“dist”文件(错误代码:EISDIR)
- 科尔多瓦的文件传输写入错误(代码 1)
- 角度$asyncValidators将错误代码传输到模板
- 接收错误代码 3,http_status空,正文空,异常状态 2
- 运行 grunt.file.copy 返回错误代码:ENOENT
- Parse.com 找不到错误代码:141 函数
- 尝试运行作业时分析错误代码 1 内部错误
- 节点 js 退出状态 8,错误代码 0 在 Mac 上运行
- 如何使用mootools确定损坏图像上的错误代码
- HTML 错误代码 206