Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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 在模板内访问并迭代Kendo UI Listview的数组属性_Javascript_Html_Kendo Ui_Kendo Grid_Kendo Mobile - Fatal编程技术网

Javascript 在模板内访问并迭代Kendo UI Listview的数组属性

Javascript 在模板内访问并迭代Kendo UI Listview的数组属性,javascript,html,kendo-ui,kendo-grid,kendo-mobile,Javascript,Html,Kendo Ui,Kendo Grid,Kendo Mobile,我有一个剑道UI移动列表视图 <ul data-role="listview" data-bind="source: customers" data-template="customer-template"/> 显然,这行代码会抛出一个错误 #for(x=0;x<customers.orders.lentgh(); x++){# <div>customers.orders.[x].OrderId</div> #}# #对于

我有一个剑道UI移动列表视图

 <ul data-role="listview" data-bind="source: customers" data-template="customer-template"/>

显然,这行代码会抛出一个错误

 #for(x=0;x<customers.orders.lentgh(); x++){#
       <div>customers.orders.[x].OrderId</div>
    #}#

#对于(x=0;x您不需要列表视图的数据源。模板将从此数据源中获得一项,您可以使用该项

还有一些其他问题:

  • 如果
    orders
    是JavaScript数组,则应通过
    length
    字段获取其长度。它不是一个方法
  • 长度
    拼写错误
  • 从JavaScript数组获取项目的正确方法是
    orders[x]
    而不是
    orders[x]
  • 要在剑道UI模板中输出值,应使用
    表达式
  • 列表视图是从
    创建的,但模板是
    。不能将
    嵌套在
    中。应改用
    元素无法自动关闭。您需要完全关闭它-
    • 我已经在下面的代码片段中解决了所有这些问题:

      <ul data-role="listview" data-bind="source: customers" data-template="customer-template"></ul>
      <script type="text/x-kendo-template" id="customer-template">
        <li>
           <div>#:CustomerName#</div>
           <div>Orders</div>
           #for(var x=0; x < orders.length; x++){#
                  <div># orders[x].OrderId #</div>
           #}#
        </li>
      </script>
      
        • #:客户名称# 命令 #对于(var x=0;x
      这里还有一个现场演示:

      <ul data-role="listview" data-bind="source: customers" data-template="customer-template"></ul>
      <script type="text/x-kendo-template" id="customer-template">
        <li>
           <div>#:CustomerName#</div>
           <div>Orders</div>
           #for(var x=0; x < orders.length; x++){#
                  <div># orders[x].OrderId #</div>
           #}#
        </li>
      </script>