在我的Enyo应用中,我有VirtualRepeater
生成Control
个,其中包含各种文字显示和IntegerPicker
。
这个转发器有两个问题:
1)如果生成了三行,单击第1行和第2行中的IntegerPicker
会在第0行的IntegerPicker
顶部显示下拉选择器UI。
2)我使用IntegerPicker
将每个setMax()
初始化为最大值。但是,如果生成三行,则行0和1中的IntegerPickers
将具有与第2行中相同的最大值。
看起来好像只创建了一个IntegerPicker
并且正在第一行使用。
我尝试用VirtualRepeater
替换我的Repeater
,并更改了我的转发器行创建功能,以返回包含IntegerPicker
的项目的新实例,而不是返回true。但是这会产生错误:
警告:enyo.Component.addComponent():重复的组件名称“itemName”违反了unique-name-under-owner规则,替换了散列中的现有组件并继续,但这是一个错误条件,应该修复。 / p>
似乎Repeater
需要他们的代表内联创建,这似乎相当不优雅。
此代码示例说明了问题:
enyo.kind({
name:"Test",
kind:enyo.Control,
components: [
{
kind: "VirtualRepeater",
onSetupRow: "setupRow",
components: [{
name: "theIP", kind: "IntegerPicker", min:0
}]
}
],
setupRow: function(inSender, inIndex) {
if (inIndex < 3) {
this.$.theIP.setMax(inIndex);
return true;
}
return false;
}
});
如何在我的应用中创建任意数量的IntegerPicker
?任何帮助表示赞赏!
答案 0 :(得分:0)
您在setupRow函数中使用IP所做的是访问特定的IntegerPicker本身,它是Virtual Repeater的子组件。要设置与该行对应的给定IntegerPicker的最大值,请为VirtualRepeater指定一个名称属性,如“PickerList”:
kind: "VirtualRepeater",
onSetupRow: "setupRow",
name: "PickerList",
components:[//this should be empty to begin with]
然后你可以像这样访问转发器中的每一行:
setupRow: function(inSender, pickerMax) {
var newPicker = new IntegerPicker(pickerMax);
this.$.PickerList.push(newPicker);
要获取VirtualRepeater中的特定行,您需要这样做:
this.$.PickerList[1];
这是一个扩展的Enyo教程,它使用了VirtualRepeater: https://developer.palm.com/content/resources/develop/extended_enyo_tutorial.html