ng-repeatsソースから見ると、for-ofを使用しているインスタンスのようには見えません。イテレータ関数を利用するために、このループをテンプレートで実現するカスタムディレクティブはありますか?イテレータng-repeatで "for ... of"を使用する
class Cache{
constructor(items){
this.cache = {
"one" : 1,
"two" : 2
};
};
// custom iterator that turns our cache into an array
// for use in "for...of" loops
[Symbol.iterator](){
var index = 0;
// turn cache object into array of its values (underscore method)
var data = _.values(this.cache);
return {
next: function(){
if(index < data.length){
return {
value: data[index++],
done: false
};
}else{
return { done:true };
}
}
};
};
};
var myCache = new Cache();
// looping my cache in simple js would look like
for(let val of myCache){
console.log(val);
}
// 1, 2
と
クラスはNG-repeatがfor...of
を実装していないと動作しないことが
<ul>
<li ng-repeat="item in myCache track by $index"></li>
</ul>
angularjs NGリピートディレクティブを提案しました。私の質問です:最小のインターフェイスの変更、またはより良いまだ、ループのfor...of
のために作られたng-repeatと同じより良い、イテレータでng-repeatディレクティブをうまく動作させる方法がありますか?
これはあなたを助けることがあります。 http://stackoverflow.com/questions/11873570/angularjs-for-loop-with-numbers-ranges –
ng-repeatの構文は 'object in array'または'(key、value)in object'です。あなたは何を達成しようとしていますか? –
が例として更新されました – anson