最初に、私は Ember.js にまったく慣れておらず、ソフトウェア開発には比較的慣れていないと言って前置きさせてください。私は、ユーザーが twitter や facebook に似た小さなテキストの更新を投稿したり、毎週の目標を作成したり、更新を投稿するときに目標ドロップダウンから選択して、オプションで投稿を目標に「適用」したりできるアクティビティ ログ アプリケーションを構築しようとしています。ユーザーが投稿を特定の目標に「適用」した回数を数えることを除いて、すべてを機能させることができました。したがって、以下のコードの簡略版を次に示します: (また、jsfiddle http://jsfiddle.net/jjohnson/KzK3B/3/をまとめました)
App = Ember.Application.create({});
App.Goal = Ember.Object.extend({
goalTitle: null,
timesPerWeek: null
});
App.Post = Ember.Object.extend({
postContent: null,
goal_name: null
});
App.postsController = Ember.ArrayController.create({
content: [
App.Post.create({ postContent: "went and played golf today, shot 69", goal_name: "Play a round of golf" }),
App.Post.create({ postContent: "went and played golf today, shot a 70", goal_name: "Play a round of golf" }),
App.Post.create({ postContent: "went to the range for an hour", goal_name: "Range practice" })
]
});
App.goalsController = Ember.ArrayController.create({
content: [
App.Goal.create({ goalTitle: 'Play a round of golf', timesPerWeek: 2 }),
App.Goal.create({ goalTitle: 'Range practice', timesPerWeek: 3 })
],
timesThisWeek: function() {
var value = "Play a round of golf";
var value2 = this.goalTitle;
return App.postsController.filterProperty('goal_name', value).get('length');
}.property('@each.goal_name')
});
だから、私はこれを理解することに近づいたと思いますが、信じられないほど単純なものを見落としていると確信していても、完全には理解できません. timesThisWeek 関数に静的な目標名の値を入れると、(var 値) timesThisWeek カウントはその特定の目標に対して機能します。しかし、ハンドルバー イテレータ (var value2) に「this」を追加しようとすると、関連する目標に対して timesThisWeek を機能させることができません。
これは非常に基本的なことだと思いますが、どんな助けでも大歓迎です!!!