jquery-ui中的重复列表未在选择下拉列表中显示所选项目

时间:2016-03-07 17:04:37

标签: javascript jquery html jquery-ui jquery-mobile

我使用JS / JQuery从ul中获取li元素并通过将其插入DOM来重复它,同时我在select元素中填写一些选项。选择元素工作正常,但所选项目不会显示在屏幕上。

此处是Plunker https://plnkr.co/edit/izy7cXfFJxypLx30C8z3?p=preview

var rooms = [
{id: '001', roomName: 'Front Room'},
{id: '002', roomName: 'Kitchen'}
];
var salesItems = [
{id: '001', itemNo: '1', room_id: ''},
{id: '002', itemNo: '2', room_id: ''},
];

var itemTemplate = $('#basket-screen-ul').html();

$('#basket-screen-ul').html('');
var htmlList = '';

salesItems.forEach(function(salesItem) {
  console.log('item ' + salesItem.itemNo);
  var htmlItem = itemTemplate;
    for (var fld in salesItem) {
        htmlItem = app.replaceAll(htmlItem, '{saleItems.' + fld + '}', salesItem[fld]);
        htmlItem = app.replaceAll(htmlItem, 'saleItems-0-', 'saleItems-' + salesItem.itemNo +  '-');
    }
    htmlList += htmlItem;      
});
$('#basket-screen-ul').html(htmlList);
window.setTimeout(function() {
    salesItems.forEach(function(saleItem) {
        rooms.forEach(function(room) {
            $('#saleItems-' + saleItem.itemNo + '-rooms_id').append($('<option></option>').attr('value',room.id).text(room.roomName));
        });

    });
});

我是否需要做些什么来让jquery-ui刷新新插入的HTML?

0 个答案:

没有答案