Jquery 错误:列表索引必须是整数,而不是str

Jquery 错误:列表索引必须是整数,而不是str,jquery,python,arrays,object,pyramid,Jquery,Python,Arrays,Object,Pyramid,我有一个表单,它预先填充了一个对象。框架:金字塔,IDE:PyCharm 在页面上,我有额外的字段供用户添加额外的电话号码和电子邮件。例如,单个phone对象{tag:work,value:555}将被推送到person对象内部的phones[]数组中。然后我需要将新信息发送回服务器 jQuery // Person var person = { username : profileData.username, firstName : "", lastName : "",

我有一个表单,它预先填充了一个对象。框架:金字塔,IDE:PyCharm

在页面上,我有额外的字段供用户添加额外的电话号码和电子邮件。例如,单个phone对象{tag:work,value:555}将被推送到person对象内部的phones[]数组中。然后我需要将新信息发送回服务器

jQuery

// Person
var person = {
    username : profileData.username,
    firstName : "",
    lastName : "",
    phones : [],
    emails : [],
    organization : "",
    title : ""
}

// Original Profile
person.firstName = $('#profile-firstname').val();
person.lastName  = $('#profile-lastname').val();
person.organization = $('#profile-company').val();
person.title  = $('#profile-title').val();

// Added Profile
var phoneObjs   = {};
var emailObjs   = {};
var extraPhones = [];
var extraEmails = [];
var addedPhones = $('.added_phone');
var addedEmails = $('.added_email');

addedPhones.each( function(i) {
    //console.log(i);
    var tag = $(this).children("label").text();
    var value = $(this).children("input").val();
    phoneObjs = $(this).map(function(i,el) {
        var $el = $(el);
        return {
            tag: tag,
            value:value
        };
    }).get();
    person.phones.push(phoneObjs);
    console.log(phoneObjs);
});
蟒蛇

def save_profile(self):
    success_msgs = ['Saved! Worry not, nothing sent to the NSA... as far as we know', "Profile Saved, doesn't it feel great to be updated?"]
    error_msgs = ['Internets are clogged up, our monkeys are checking it out', 'Hmm, everything look correct below?', "A BUG! Probably in our code, we're checking it out"]
    try:
        json = self.request.json_body
        first_name = str(json['firstName'])
        last_name = str(json['lastName'])
        organization = str(json['organization'])
        title = str(json['title'])
        phones = (json['phones'])
        emails = (json['emails'])
        self.profiles.update(firstName=first_name, lastName=last_name, organization=organization, title=title, emails=emails, phones=phones)
        #print phones
        value = {'result': 'success', 'message': random.choice(success_msgs)}
    except Exception, err:
        print err
        value = {'result': 'error', 'message': random.choice(error_msgs)}

    #returns a json response
    return self.respond(value)
profile.update

if tools.not_blank(phones):
        lst = phones
        cnt = len(lst)
        current = profile.phones
        for x in xrange(cnt):
            o = lst[x]
            #key = o.get("key", o.get("guid", None))
            lbl = o["label"]
            tag = o.get("tag", None)
            c = [c for c in current if c.label == lbl]
            c = c[0] if len(c) > 0 else None
            if c:
                m, k = self.codex.decode_composite(c.id)
                if tools.not_blank(tag):
                    tag = tag.lower().title()
                    if c.tag != tag:
                        c.tag = tag
                        self.get_query("UPDATE member_phone SET Type = @tag WHERE ID = @id;", {"tag": tag, "id": k}).update()
            else:
                #create a new email address for this member
                self.members.register_phone_number(member=member, telephone=lbl, tag=tag)

    if tools.is_blank(remove):
        return profile

IDE将在此处抛出“列表索引必须是整数,而不是str”错误

有什么想法吗?我不确定这里出了什么问题

self.profiles.update(firstName=first_name, lastName=last_name, organization=organization, title=title, emails=emails, phones=phones)

添加了字段的表单在此创建正确的对象


当我深入self.profiles.update()时,我的jQuery出现了问题

第一个问题是lbl=0[“label”]最初的开发者希望手机有标签,而不是我传递的值

第二件事,我们的iOS开发人员指出,我有一个嵌套数组
[[]]
,但我没有注意到,所以回到jQuery:

必须更改:
person.phones.push(phoneObjs)
to
person.phones=phoneObjs

现在它只返回电话的
[]
,没有列表错误:)

更新的jQuery

addedPhones.each( function(i) {
    var tag = $(this).children("label").text();
    var value = $(this).children("input").val();
    phoneObjs = $(this).map(function(i,el) {
        var $el = $(el);
        return {
            tag: tag,
            label:value
        };
    }).get();
    person.phones = phoneObjs;
    console.log(phoneObjs);
});

你在说什么?告诉我们这是什么样的框架,或者至少告诉我们什么是
self.profiles
可能也会有帮助。请发布回溯信息好吗?你在
self.profiles.update()
方法中做什么?很抱歉,这是PyCharm,在金字塔框架中,将profiles.update添加到原始代码中。。。事实上,我的问题是,我在一个数组中传递了一个嵌套数组,我认为这是导致问题的原因
addedPhones.each( function(i) {
    var tag = $(this).children("label").text();
    var value = $(this).children("input").val();
    phoneObjs = $(this).map(function(i,el) {
        var $el = $(el);
        return {
            tag: tag,
            label:value
        };
    }).get();
    person.phones = phoneObjs;
    console.log(phoneObjs);
});