动态加载后的jquery设计

时间:2015-06-04 17:12:28

标签: javascript jquery html jquery-mobile

我有一个简单的javascript应用程序,它提供了一些BLE信息。

一切正常,但我在使用JQuery Mobile Library时遇到了一些问题。

我希望整个App都在简单的JQuery Data-Theme =" b"中。由于List-View是通过addDevice函数动态创建的,因此它不能与JQuery一起使用。当我在没有.append()命令的情况下尝试它时,它正在工作 - 所以我的JQuery Mobile Library没有问题。 我还尝试使用.append()命令添加data-theme属性,其中包含:

Private _Time_HH As Integer
Public Property Time_HH() As String
    Get
        Return _Time_HH.ToString()
    End Get
    Set(value As String)
        Dim int As Integer

        If Integer.TryParse(value, int) = False Then
            MessageBox.Show("Error")
        End If

        _Time_HH = int
        OnPropertyChanged("Time_HH")
    End Set
End Property

但仍无法正常工作..

以下是我的html和javascript文件的输出。

HTML:

    $devices.attr("data-theme" , "b");

javascript:

 <ul data-role="listview" class="devices" id="myresult" data-theme="b"></ul>
    <div data-role="content" id="result">
         <script type="text/template" id="device">   
            <ul data-role="listview" data-theme="b">
                <li data-address="{0}">
                    <h2>{1}</h2>
                    <h2>RSSI: {2}</h2>
                </li> 
            </ul>
        </script>   
    </div>

也许有人知道我的代码有什么问题......

1 个答案:

答案 0 :(得分:0)

我不知道你想在这里实现什么。但是您可以使用下面的代码在Jquery Mobile中的listview中动态附加数据。

HTML:

<div data-role="content">
<ul data-role="listview" class="devices" id="myresult" data-theme="b"> 
</ul>
</div>

Javascript:非常简单易用。

function addDevice(address,name,rssi) {

var result ="";

for (int i = 1; i<50;i++) { result += '<li>'+address+'<h2> '+name+'</h2>' result +='<h2> RSSI : '+rssi+'</h2>' result +='</li>' } $('#myresult').append(result); }

您还可以使用jquery mobile查看以下链接以获取动态列表。 http://jsfiddle.net/Gajotres/8uac7/