在iron-data-table中,当我单击任何当前选定的行时,我希望selected-item ({{selectedItem}})对象反映当前(和以前)选定的行;但是,它变成了null。
重新创建问题的步骤:
selected-item ({{selectedItem}})对象现在是null。如何纠正这一点,使所选对象是新选定的行(这是以前选定的行)而不是null?
http://jsbin.com/xucemijada/1/edit?html,console,output
<!DOCTYPE html>
<html>
<head>
<base href="https://polygit.org/polymer+:master/iron-data-table+Saulis+:master/components/">
<link rel="import" href="polymer/polymer.html">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="iron-ajax/iron-ajax.html">
<link rel="import" href="paper-button/paper-button.html">
<link rel="import" href="iron-data-table/iron-data-table.html">
<link rel="import" href="iron-data-table/default-styles.html">
</head>
<body>
<x-foo></x-foo>
<dom-module id="x-foo">
<template>
<style>
</style>
[[_computeSelectedStr(selectedItem)]]
<iron-ajax
auto
url="https://saulis.github.io/iron-data-table/demo/users.json"
last-response="{{users}}"
>
</iron-ajax>
<iron-data-table id="grid"
selection-enabled
items="[[users.results]]"
selected-item="{{selectedItem}}"
>
<data-table-column name="Picture" width="50px" flex="0">
<template>
<img src="[[item.user.picture.thumbnail]]">
</template>
</data-table-column>
<data-table-column name="First Name">
<template>[[item.user.name.first]]</template>
</data-table-column>
<data-table-column name="Last Name">
<template>[[item.user.name.last]]</template>
</data-table-column>
<data-table-column name="Email">
<template>[[item.user.email]]</template>
</data-table-column>
</iron-data-table>
</template>
<script>
(function(){
'use strict';
Polymer({
is: 'x-foo',
observers: [
'_selectedItemChanged(selectedItem)' ,
],
_selectedItemChanged: function(ob) {
console.log('selectedItem', ob);
},
_computeSelectedStr: function(ob) {
return JSON.stringify(ob);
},
});
})();
</script>
</dom-module>
</body>
</html>发布于 2016-08-02 06:10:44
当第二次单击一行时,项目将被取消选中,而在null中使用selectedItem来反映这一点。类似地,在多选择模式下,当没有选择任何内容时,selectedItems是空的。
因为v1.0.1 <iron-data-table>会触发deselecting-item事件,可以用来防止取消选举。
table.addEventListener('deselecting-item', function(e) { e.preventDefault(); });
我更新了您的JSBin,以演示如何使用此事件:http://jsbin.com/dubuyoy/edit?html,console,output
https://stackoverflow.com/questions/38707525
复制相似问题