带有数据传递和移动视图的jquery动态复选框

时间:2012-02-10 22:23:20

标签: jquery list mobile jquery-mobile checkbox

我在移动应用程序中,我想创建动态的复选框列表,将一些数据传递给另一个函数。我希望这个复选框列表看起来像移动应用程序

http://jquerymobile.com/demos/1.0a4.1/docs/forms/forms-checkboxes.html

而不是简单的链接...

这是我的代码

        for (i = 0; i < len; i += 1) {
            row = resultflatname.rows.item(i);

            if (row.flatdescription == flatdescription) {
                if (row.receiptno == 0){
                        items.push('<input type="checkbox" name="code_'+ i +'" id="code_'+ i +'" value="' + row.amount + '" previous="' + row.pastpayments + '" barcode="' + row.barcode + '" todayp="' + row.todaypayments + '"/><label for="code_'+ i +'">' + row.period +'..........'+ row.amount+'</label></br>');
                allbarcode[i] = row.barcode;
                previouspayments = previouspayments + row.pastpayments;
                previouspayments = previouspayments.toFixed(2);
                sofeilon = sofeilon + row.amount;
                sofeilon = sofeilon.toFixed(2);
                total = total + row.amount - row.pastpayments;
                total = total.toFixed(2);

                } else {

                if ((row.receiptno > 0) && (row.todaypayments < row.amount - row.pastpayments)){
                        items.push('<input type="checkbox" name="code_'+ i +'" id="code_'+ i +'" value="' + row.amount + '" previous="' + row.pastpayments + '" barcode="' + row.barcode + '" todayp="' + row.todaypayments + '"/><label for="code_'+ i +'">' + row.period +'..........'+ row.amount+'</label></br>');
                allbarcode[i] = row.barcode;
                previouspayments = previouspayments + row.pastpayments;
                previouspayments = previouspayments.toFixed(2);
                sofeilon = sofeilon + row.amount;
                sofeilon = sofeilon.toFixed(2);
                total = total + row.amount - row.pastpayments;
                total = total.toFixed(2);

                }
                }
            }
            list.html(items.join('\n'));

        }

1 个答案:

答案 0 :(得分:0)

不是将锚元素推送到数组并加入它们,而是在推送到数组之前将它们包装在list-item元素中:

items.push('<li><input type="checkbox" name="code_'+ i +'" id="code_'+ i +'" value="' + row.amount + '" previous="' + row.pastpayments + '" barcode="' + row.barcode + '" todayp="' + row.todaypayments + '"/><label for="code_'+ i +'">' + row.period +'..........'+ row.amount+'</label></li>');

然后当您加入表格时,添加<ul>开始和结束标记:

list.html('<ul data-role="listview">' + items.join('') + '</ul>').trigger('create');

.trigger('create');很重要,因为它会使jQuery Mobile框架初始化刚刚添加到DOM的新listview窗口小部件。

我使用.trigger('create')已经有一段时间了,所以我不记得你是否可以在父元素上调用它(我很确定你可以)或者你是否必须选择新的{调用<ul>前的{1}}元素:

.trigger('create')