私は次の設定をしています:
App.module('TestUsers.Views', function(TestUsersViews, App, Backbone, Marionette, $, _) {
TestUsersViews.UsersItemView = Marionette.ItemView.extend({
template: testUsersItemViewTmpl
, tagName: 'tr'
, templateHelpers: {
handleUndefined: function(val) {
return (_.isUndefined(val) ? '' : val);
}
}
});
TestUsersViews.UsersTable = Marionette.CompositeView.extend({
template: testUsersTmpl
, tagName: 'table'
, className: 'h-center'
, itemView: TestUsersViews.UsersItemView
, itemViewContainer: 'tbody'
, initialize: function() {
this.listenTo(this.collection, 'reset', function() {
this.appendHtml = function(collectionView, itemView, index) {
collectionView.$el.append(itemView.el);
}
});
}
});
});
返される Collection の構造は次のとおりです。
[ { "apiStandardProfileRequest": { "headers": { "_total": 1, "values": [ { "name": "x-li-auth-token", "value": "name:ksBx" } ] } , "url": " http://api.linkedin.com/v1/people/jGEI3X15sx " }, "firstName": "Eileen", "headline": "Kforce Professional Staffing のデリバリー担当マネージング ディレクター", "id" : "jGEI3X15sx", "業界": "人員配置と採用", "lastName": "Adams (LION)", "location": { "country": { "code": "us" },"name": "Greater Boston Area" }, "pictureUrl": " http://mclnkd.licdn.com/mpr/mprx/0_y_g-snorc6G3qFIa->bjSsz4yRb6un3EaOkWSszeCX3-yW5gmr5SOqvpuzEQPz6wGg8x2vtspSH8c", "siteStandardProfileRequest": { "url": " http://www.linkedin.com/profile/view ?>id=3633999&authType=name&authToken=ksBx&trk=api*a249733*s257591}*." .. ]
データをレンダリングするための私のテンプレートは次のとおりです。
<td id="<%= id %>"><img src="<%= pictureUrl %>" width="16" height="16"/><%= firstName %> <%= lastName %></td>
<td><%= headline %></td>
<td></td>
<td><%= location.country.code %></td>
<td><%= location.name %></td>
<td><a href="<%= siteStandardProfileRequest.url %>">Full Profile</a></td>
ただし、一部のユーザーは「pictureUrl」を持っておらず、「Uncaught ReferenceError: pictureUrl is not defined」というエラーが表示されます。未定義の値が処理されないという私が間違っていることはわかりません。これは簡単な修正であり、助けがあれば幸いです。