2016-11-29 8 views
2

私は、次のdom-repeatテンプレートがある場合:計算さプロパティ

<template is="dom-repeat" items="{{myFiles}}" as="file"> 
    <span> 
    {{file.createDate}} <br/> 
    </span> 
</template> 

と私はfile.createDateをフォーマットしたいと思い、これを行うにはcomputed propertyを使用する方法がありますか?

答えて

3

いいえ、あなたは、アイテム(またはこの場合は、そのサブプロパティ)にcomputed bindingを使用する必要があります。また

// template 
<template is="dom-repeat" items="{{_myFiles}}" as="file"> 
    <span>{{_formatDate(file.createDate)}}</span> 
</template> 

// script 
Polymer({ 
    _formatDate: function(createDate) { 
    return /* format createDate */; 
    } 
}); 

、あなたが計算されたプロパティを使用することができ(例えば、_myFilesという名前)myFiles

// template 
<template is="dom-repeat" items="{{_myFiles}}" as="file"> 
    <span>[[file.createDate]]</span> 
</template> 

// script 
Polymer({ 
    properties: { 
    myFiles: Array, 
    _myFiles: { 
     computed: '_preprocessFiles(myFiles)' 
    } 
    }, 
    _preprocessFiles: function(files) { 
    return files.map(x => { 
     x.createDate = /* format x.createDate */; 
     return x; 
    }); 
    } 
}); 
+0

私のような私の計算プロパティを定義する必要がありました: MyFilesフォルダ:dom-repeat反復する前に、すべてのアイテムを処理し、配列、{ タイプ:配列 計算: '_preprocessFiles(myFiles)'、 通知:true } –

関連する問題