追加不会逐行读取

时间:2015-09-22 05:06:06

标签: python django append

这是我的代码:

var win = Titanium.UI.createWindow({
    title:"Accessing the photo album",
    backgroundColor:"#FFFFFF",
    exitOnClose:true
});

var button = Titanium.UI.createButton({
    title:"Open the photo gallery",
    width:180,
    height:48,
    bottom: 12,
    zIndex:2
});

button.addEventListener("click", function(e){
    //Open the photo gallery
    Titanium.Media.openPhotoGallery({
        //function to call upon successful load of the gallery
        success:function(e){
            //e.media represents the photo or video
            var imageView = Titanium.UI.createImageView({
                image:e.media,
                width:320,
                height:480,
                top:12,
                zIndex:1
            });

            win.add(imageView);
        },
        error:function(e){
            alert("There was an error");
        },
        cancel:function(e){
            alert("The photo gallery was cancelled");
        },
        //Allow editing of media before success
        allowEditing:true,
        //Media types to allow
        mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
        //The other is Titanium.Media.MEDIA_TYPE_VIDEO
    });
});

win.add(button);

win.open();

我认为我在第65-69行遇到了问题,因为在我的taskList中,它只附加了id,name和parent_task_id的最后一个值4次。它不会逐行追加。你能检查一下吗?

1 个答案:

答案 0 :(得分:0)

我试图重现你的问题,但是,我无法重现。

请检查下面的代码。

from lxml import etree as ET
task_xml = """<?xml version="1.0" encoding="utf-8"?>
    <django-objects version="1.0">
<object model="task.task" pk="31">
<field name="name" type="CharField">New Task</field>
<field name="parent_task_id" type="IntegerField">0</field>
</object>
<object model="task.task" pk="32">
<field name="name" type="CharField">New Task</field>
<field name="parent_task_id" type="IntegerField">0</field>
</object>
<object model="task.task" pk="33">
<field name="name" type="CharField">New Task</field>
<field name="parent_task_id" type="IntegerField">31</field>
</object>
<object model="task.task" pk="34">
<field name="name" type="CharField">New Task</field>
<field name="parent_task_id" type="IntegerField">31</field>
</object>
</django-objects>"""

xmlData = ET.fromstring(task_xml)
taskList = []

for obj in xmlData.iter("object"):
    parent_task_id = obj.find("field[@name='parent_task_id']").text
    taskList.append(parent_task_id)

print taskList

输出:

$ python /tmp/test.py
['0', '0', '31', '31']

请您更正我的代码,以便重现您的问题

注意:这不是答案,但我不能在评论中提供这么多代码