自定义ListView Row,无法再选择行
这是我的 ScrollView:
middle: SC.ScrollView.design({
layout: { top: 36, bottom: 32, left: 0, right: 0 },
backgroundColor: '#ccc',
contentView: SC.ListView.design({
contentBinding: 'Spanish.wordsController.arrangedObjects',
selectionBinding: 'Spanish.wordsController.selection',
contentValueKey: "word",
contentDisplayProperties: 'word english'.w(),
selectOnMouseDown: YES,
exampleView: Spanish.CustomListItemView
})
})
这是我的自定义 listView 行:
Spanish.CustomListItemView = SC.View.extend({
render: function(context, firstTime){
var content = this.get('content');
var word = content.get('word');
var english = content.get('english');
context = context.begin().push(' %@ (%@)'.fmt(word,english)).end();
return sc_super();
}
});
上面的内容按预期工作,只是我无法再选择视图。当我注释掉“exampleView:Spanish.CustomListItemView”时,我可以选择行,但它们的格式不再正确。为什么使用 exampleView 时无法再选择行?
Here's my ScrollView:
middle: SC.ScrollView.design({
layout: { top: 36, bottom: 32, left: 0, right: 0 },
backgroundColor: '#ccc',
contentView: SC.ListView.design({
contentBinding: 'Spanish.wordsController.arrangedObjects',
selectionBinding: 'Spanish.wordsController.selection',
contentValueKey: "word",
contentDisplayProperties: 'word english'.w(),
selectOnMouseDown: YES,
exampleView: Spanish.CustomListItemView
})
})
and here is my custom listView row:
Spanish.CustomListItemView = SC.View.extend({
render: function(context, firstTime){
var content = this.get('content');
var word = content.get('word');
var english = content.get('english');
context = context.begin().push(' %@ (%@)'.fmt(word,english)).end();
return sc_super();
}
});
The above works as expected, except that I can no longer select views. When I comment out "exampleView: Spanish.CustomListItemView" I can select rows, but they are no longer formatted properly. Why can I no longer select rows when I use exampleView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
相反,子类化 SC.ListItemView。
删除
return sc_super();
行。将
context = context.begin().push(' %@ (%@)'.fmt(word,english)).end();
行更改为:它应该可以工作现在。
Subclass SC.ListItemView instead.
Remove the
return sc_super();
line.Change the
context = context.begin().push(' %@ (%@)'.fmt(word,english)).end();
line to:It should work now.
在获得 IRC 的帮助后,我进行了以下更改,解决了问题:
我对错误的类进行了子类化(请注意第一行)
After getting help on IRC, I made the following changes which fixed the problem:
I was subclassing the wrong class (note the first line)