Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有Javascript模板的innerHTML输出_Javascript_Jquery_Html_Templates_Bluetooth Lowenergy - Fatal编程技术网

带有Javascript模板的innerHTML输出

带有Javascript模板的innerHTML输出,javascript,jquery,html,templates,bluetooth-lowenergy,Javascript,Jquery,Html,Templates,Bluetooth Lowenergy,对于我的项目,我必须扫描BLE标签,并显示它们的RSSI以确定是否接近 BLEs的输出使用JavaScript模板 <body> <div id="header" data-role="header" data-theme="b"> <h1>BLE overview</h1> </div> </br> <div data-role="

对于我的项目,我必须扫描BLE标签,并显示它们的RSSI以确定是否接近

BLEs的输出使用JavaScript模板

  <body>
     <div id="header" data-role="header" data-theme="b">
        <h1>BLE overview</h1>
     </div>          
        </br>
     <div data-role="content" id="home">
        <a href="#" data-role="button" data-theme="b" data-inline="true" class="pure-button initialize">Initialize</a>
        <a href="#" data-role="button" data-theme="b" data-inline="true" class="pure-button startScan">Start Scan</a>
        <a href="#" data-role="button" data-theme="b" data-inline="true" class="pure-button stopScan">Stop Scan</a>
     </div>
        <ul data-role="list-view" class="devices"></ul>
     <div data-role="content id="result">
       <script type="text/template" id="device">     //start of the schript tag and output of the scanned BLEs
          <ul data-role="listview">
             <li data-address="{0}">
                <h2>{1}</h2>
                <a href="#" data-role="button" data-theme="b" class="pure-button connect">Connect</a>
                <div id="rssiop"> RSSI:  <div>   // value of the RSSI
                </br>   
            </li> 
         </ul>
      </script> 
   </div>       
这是一个函数,它给出了扫描出的文件的名称和地址

function addDevice(address, name)
{
  var $devices = $(".devices");

  var $check = $devices.find("li[data-address='{0}']".format(address));

  if ($check.length > 0)
  {
    return;

  }
  console.log("Mein RSSI: " + obj.rssi);
  document.getElementById("rssiop").innerHTML = "The RSSI value is:";
  var template = $("#device").text().format(address, name);

  $devices.append(template);   
}
所以一切都正常,当我将div标记放在模板脚本上方时,我可以看到RSSI。有人能理解为什么模板部分中的innerHTML不起作用吗

我想出来了:

问题是innerHTML不起作用,因为我对列表输出使用了append()-命令。我只需将rssi参数添加到addDevices函数中,就可以了

addDevice功能的正确代码:

function addDevice(address, name, rssi)
{
  var $devices = $(".devices");

  var $check = $devices.find("li[data-address='{0}']".format(address));

  if ($check.length > 0)
  {
    return;

  }
  var template = $("#device").text().format(address, name, rssi);

  $devices.append(template);

} 

什么构成不工作?使用innerHTML的部分,因为脚本标记是类型模板。
function addDevice(address, name, rssi)
{
  var $devices = $(".devices");

  var $check = $devices.find("li[data-address='{0}']".format(address));

  if ($check.length > 0)
  {
    return;

  }
  var template = $("#device").text().format(address, name, rssi);

  $devices.append(template);

}