Apache flex 将容器动态添加到动态容器
我有一个循环,它遍历一本书中的数据并显示出来。这本书的布局不一致,所以我尝试用两种不同的方式来展示它。第一种方法(工作正常)是将该节中的文本加载到面板并显示它。第二种方法是创建新面板(面板创建精细),然后向该面板添加可折叠面板(嵌套)。下面是else循环中的代码Apache flex 将容器动态添加到动态容器,apache-flex,actionscript,Apache Flex,Actionscript,我有一个循环,它遍历一本书中的数据并显示出来。这本书的布局不一致,所以我尝试用两种不同的方式来展示它。第一种方法(工作正常)是将该节中的文本加载到面板并显示它。第二种方法是创建新面板(面板创建精细),然后向该面板添加可折叠面板(嵌套)。下面是else循环中的代码 else if (newPanel == false){ // simpleData is just for the title bar of the new panel
else if (newPanel == false){
// simpleData is just for the title bar of the new panel
// otherwise the panel has no content
var simpleData:Section = new Section;
simpleData.section_letter = item.section_letter;
simpleData.letter_title = item.letter_title;
simpleData.section_id = item.section_id;
simpleData.title = item.title;
simpleData.bookmark = item.bookmark;
simpleData.read_section = item.read_section;
var display2:readPanel02 = new readPanel02;
//item is all the data for the new text
display2.id = "panel"+item.section_id;
//trace(display2.name);//trace works fine
// set vars is how I pass in the data to the panel
display2.setVars(simpleData);
studyArea.addElement(display2); // displays fine
newPanel = true;
//this is where it fails
var ssPanel:subSectionPanel = new subSectionPanel;
//function to pass in the vars to the new panel
ssPanel.setSSVars(item);
//this.studyArea[newPanelName].addElement(ssPanel);
this["panel"+item.section_id].addElement(ssPanel);
我得到的错误是:ReferenceError:error#1069:在components.readTest上找不到属性面板4.4,并且没有默认值
我尝试设置“name”属性而不是“id”属性。任何帮助都将不胜感激。我被难住了。谢谢 这是我提出的解决方案。我让新的readPanel创建子面板。我添加了else语句以使其更有意义。readPanel创建第一个子面板,对于子面板的每个后续需求,它会按名称引用另一个面板,并调用创建新子面板的面板中的公共函数。以下是创建主面板的代码:
else if (newPanel == false){
var display2:readPanel02 = new readPanel02;
studyArea.addElement(display2);
display2.name = "panel"+item.section_id;
display2.setVars(item);
newPanel = true;
}
else{
var myPanel:readPanel02 = studyArea.getChildByName("panel"+item.section_id) as readPanel02;
myPanel.addSubSection(item);
}
以下是面板中的功能:
public function setVars(data:Section):void
{
myS = data;
textLetter = myS.section_letter;
textLetterTitle = myS.letter_title;
textSection = myS.section_id;
textTitle = myS.title;
myS.bookmark == 0 ? bookmarked = false : bookmarked = true;
myS.read_section == 0 ? doneRead = false : doneRead = true;
showTagIcon();
showReadIcon();
addSubSection(myS);
}
public function addSubSection(data:Section):void{
var ssPanel:subSectionPanel = new subSectionPanel;
ssPanel.setSSVars(data);
myContentGroup.addElementAt(ssPanel, i);
i++;
}
我不明白你想做什么。您只想显示书本数据吗?不要把注意力集中在如何做上,而要集中在做什么上。从你的代码看,我可以告诉你,你所做的远远不是最佳的。@J_a__X我不知道你是否看到了,我自己回答了。你觉得那里的代码怎么样?我对optimal知之甚少,所以我想知道你的意见。再说一次,我不能发表评论,因为我不知道你想用这一切实现什么。你想解决的问题是什么?@J_A_X文本来自一本书。这本书前后矛盾。有些章节只是一段,有些是15页。对于15页的页面,我将它们分为几个小节,并将每个小节显示在一个可折叠的面板中,以便于导航。代码应该是1.从sql调用中获取结果2.循环结果以决定如何显示它们3.部分显示在相应的面板中。正如我上面所说,我确实弄明白了(下面)。只是想得到比我更了解的人的意见,因为你指出这是多么不理想。谢谢。什么样的导航?显示书籍或移动到下一部分时的行为是什么?在“页面”之间使用TLF文本字段链接无法实现这一点,有什么原因吗?