我有以下设置:
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”,“行业”:“人员配备和招聘”,“姓氏”:“亚当斯(LION)”,“位置”:{“国家”:{“代码”:“我们”},“名称”:“大波士顿地区”},“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 }1*s25759}9 ..]
我呈现数据的模板是:
<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”,我收到“未捕获的 ReferenceError:pictureUrl 未定义”错误。我不确定我做错了什么,未处理未定义的值。我相信这是一个简单的修复,任何帮助表示赞赏。