たとえば、画面の幅を計算し、その結果を 0 と 3 の間の数値に割り当てたいとします。私はこれを行うために使用しようとしiron-media-query
ています。
true
クエリの 1 つが の値を返し、他の 3 つのクエリが を返す (コンソールに記録される) ことを期待していますfalse
。ただし、それらはすべて の値を返しますundefined
。
私は何を間違っていますか?
参考までに、これを解決した後、 when isqueryResult()
の値を格納するメソッドに条件を追加する予定です。index
queryMatches
true
queryResult: function() {
...
if(this.queryMatches) {
this.set('mediaWidth', index);
}
...
}
http://jsbin.com/kamusivebi/1/edit?html,console,output
<!doctype html>
<head>
<meta charset="utf-8">
<base href="https://polygit.org/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="polymer/polymer.html" rel="import">
</head>
<body>
<dom-module id="x-element">
<template>
<style></style>
<template is="dom-repeat"
id="page"
items="[[queries]]"
>
<iron-media-query id="query"
full
query="[[item]]"
query-matches="{{queryMatches}}"
>
<span hidden>{{queryResult(index)}}</span>
</iron-media-query>
</template>
</template>
<script>
(function(){
Polymer({
is: "x-element",
properties: {
queryMatches: Boolean,
queries: {
type: Object,
value: function() {
return [
'(max-width: 699px)' ,
'(min-width: 700px) AND (max-width: 899px)' ,
'(min-width: 900px) AND (max-width: 1124px)' ,
'(min-width: 1125px)' ,
];
},
},
},
queryResult: function(index) {
this.set('mediaWidth', index);
console.log('mediaWidth', this.mediaWidth);
console.log('queryMatches', this.queryMatches);
},
});
})();
</script>
</dom-module>
<x-element></x-element>
</body>