Sorting Polymer 1.x:dom repeat中使用的排序示例
请显示代码(理想情况下是一个正常工作的JSbin),演示如何在Sorting Polymer 1.x:dom repeat中使用的排序示例,sorting,polymer,polymer-1.0,Sorting,Polymer,Polymer 1.0,请显示代码(理想情况下是一个正常工作的JSbin),演示如何在dom repeat元素中正确使用sort属性 https://www.polymer-project.org/1.0/docs/devguide/templates.html#filtering-和排序列表 <template is="dom-repeat" sort="_sortItems"> ... </template> ... _sortItems: function() { // What fu
dom repeat
元素中正确使用sort属性
https://www.polymer-project.org/1.0/docs/devguide/templates.html#filtering-和排序列表
<template is="dom-repeat" sort="_sortItems">
...
</template>
...
_sortItems: function() {
// What function goes here?
}
...
...
_sortItems:function(){
//这里有什么功能?
}
另外,有关我如何使用它的更多详细信息。
[[item.num]]
聚合物({
是:“我的元素”,
就绪:函数(){
这个数字=[{
数目:1
}, {
总数:3
}, {
总数:2
}, ];
},
_mySort:函数(项1、项2){
返回item1.num>item2.num;
}
});
通过使用标准排序函数表示法(即a
、b
变量和-
减法运算符,而不是不等式(例如,
),对公认答案进行了小幅度改进
http://plnkr.co/edit/f58W9AXJIXsHRUh3liY5?p=preview
<html>
<head>
<title>Sort</title>
<script data-require="polymer@*" data-semver="1.0.0" src="http://www.polymer-project.org/1.0/samples/components/webcomponentsjs/webcomponents-lite.js"></script>
<script data-require="polymer@*" data-semver="1.0.0" src="http://www.polymer-project.org/1.0/samples/components/polymer/polymer.html"></script>
<base href="http://element-party.xyz/" />
<link rel="import" href="all-elements.html" />
</head>
<body>
<dom-module id="my-element">
<template>
<template is="dom-repeat" items={{numbers}} sort="_mySort">
<div>[[item.num]]</div>
</template>
</template>
<script>
Polymer({
is: "my-element",
ready: function() {
this.numbers = [{
num: 1
}, {
num: 3
}, {
num: 2
}, ];
},
_mySort: function(a, b) {
return b.num - a.num;
}
});
</script>
</dom-module>
<my-element></my-element>
</body>
</html>
分类
[[item.num]]
聚合物({
是:“我的元素”,
就绪:函数(){
这个数字=[{
数目:1
}, {
总数:3
}, {
总数:2
}, ];
},
_mySort:函数(a,b){
返回b.num-a.num;
}
});
<html>
<head>
<title>Sort</title>
<script data-require="polymer@*" data-semver="1.0.0" src="http://www.polymer-project.org/1.0/samples/components/webcomponentsjs/webcomponents-lite.js"></script>
<script data-require="polymer@*" data-semver="1.0.0" src="http://www.polymer-project.org/1.0/samples/components/polymer/polymer.html"></script>
<base href="http://element-party.xyz/" />
<link rel="import" href="all-elements.html" />
</head>
<body>
<dom-module id="my-element">
<template>
<template is="dom-repeat" items={{numbers}} sort="_mySort">
<div>[[item.num]]</div>
</template>
</template>
<script>
Polymer({
is: "my-element",
ready: function() {
this.numbers = [{
num: 1
}, {
num: 3
}, {
num: 2
}, ];
},
_mySort: function(a, b) {
return b.num - a.num;
}
});
</script>
</dom-module>
<my-element></my-element>
</body>
</html>