2016-07-25 63 views
1

如何让我的ListView循环访问对象属性timetableRecords。我用google搜索,但无法找到办法。数据的Kendo UI ListView消耗数组对象

实施例(招摇响应模型模式):

{ 
    "from": { 
    "name": "string" 
    }, 
    "to": { 
    "name": "string" 
    }, 
    "price": 0, 
    "date": "2016-07-25T11:52:52.674Z", 
    "timetableRecords": [ 
    { 
     "departure": "2016-07-25T11:52:52.675Z", 
     "arrival": "2016-07-25T11:52:52.675Z" 
    } 
    ], 
    "fetchedOn": "2016-07-25T11:52:52.675Z" 
} 

HTML:

<div id="timetableRecords"></div> 

<script type="text/x-kendo-template" id="template"> 
    <div class="timetable-record"> 
     <p>#:departure#</p> 
     <p>#:arrival#</p> 
    </div> 
</script> 

的JavaScript:

$('#timetableRecords').kendoListView({ 
    template: kendo.template($("#template").html()), 
    dataSource: { 
     transport: { 
      read: { 
       type: 'GET', 
       url: 'api/timetable?from=station_name1&to=station_name2', 
       dataType: 'json' 
      } 
     } 
    } 
}); 

回答

0

既然你发布了这个版本已经有一段时间了,但我有一个解决方案给你(怀疑你仍然需要它)。

的schema.parse()事件可以帮助您:

用于服务器响应之前执行。用它来预处理或解析服务器响应。

这里是你的更新数据源是如下:

dataSource: { 
    transport: { 
    read: { 
     type: 'GET', 
     url: 'api/timetable?from=station_name1&to=station_name2', 
     dataType: 'json' 
    } 
    }, 
    schema: 
    parse: fucntion(e) { 
     return e.timetableRecords 
    } 
} 

这样,你的数据源是处理“timetableRecords”的列表,你的模板将是有效的。

祝你好运,

格兰特