問題:
コードでリストビューの最初の要素を選択して変更イベントをトリガーすると、イベントは1回だけ発生します。リストビュー項目をクリックして変更イベントをトリガーすると、変更イベントが 2 回トリガーされます。
この2番目のイベントを引き起こす可能性のあるもの、それを防ぐ方法はありますか?
HTML コード:
<div id="overview">
<div id="listView"></div>
</div>
<!-- Used lib source loaded from lib server, for developers -->
<link rel="stylesheet" type="text/css" href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css" />
<link rel="stylesheet" type="text/css" href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.default.min.css" />
<script src="http://cdn.kendostatic.com/2013.2.716/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<!-- Custom libs loaded from meter, for customers/developers (very fast <0.3sec) -->
<script type="text/javascript" src="/MeasCon/Scripts/current_values.js"></script>
Javascript コード:
/* JQuery function that is called when the DOM is done loading */
$(document).ready(function ()
{
/* The HTML template code for the current values overview listview */
/* .join is for multi line in javascript */
var overview_template = [
'<div class="overview_content" id="#:name#" >',
'<div class="overview_content_textbox">',
'<span class="overview_content_textbox_text">#:test#</span>',
'</div>',
'<div class="overview_content_led_box">',
'<span class="led_box"><img class="led" src="/MeasCon/Content/IMAGES/#= led #.png"></span>',
'</div>',
'</div>'
].join("\n");
/* the datasource for the overview listview */
var overview_datasource = new kendo.data.DataSource(
{
transport:
{
read:
{
url: "../../Content/current_values_overview.json",
dataType: "json"
}
},
});
/* populating the listview with the datasource as defined by the template */
$("#listView").kendoListView(
{
template: kendo.template(overview_template),
dataSource: overview_datasource,
selectable: true,
change: function()
{
var idx = this.select().index();
var item = this.dataSource.view()[idx];
alert(item.name);
},
dataBound: function()
{
//Fires when the list view has received data from the data source and it is already rendered.
// get a reference to the list view widget
var listView = $("#listView").data("kendoListView");
// selects first list view item
listView.select(listView.element.children().first());
}
});
});
JSON ファイル
[
{
"name": "Performance",
"led": "ok_green"
}
]