我已经从数据库中检索了总裁,并创建了一个列表。现在,我需要根据用户指定的pname检索4位数的密码。下面是生成的列表。
['George Bush 6182', 'John Kennedy 5860', 'Barrack Obama 6394', 'Harry Truman 6478', 'Richard Nixon 7155']
我尝试遍历列表,但没有成功。
full_list = []
pName = message[cmd_index + 2]
p_map_snapshot = db_root.child('pMap').get()
p_id = p_map_snapshot[message[cmd_index + 1].lower()]
roster_snapshot = db_root.child('rosters').child(p_id).get()
print (pName)
for prez in roster_snapshot:
full_list.append((prez['firstName'] + " " + prez['lastName'] + " " + str(prez['pinId'])))
#LOOP HERE?
#if pName == ?
#print(full_list)
答案 0 :(得分:0)
您不需要首先构建new Vue({
el: "#app",
data: () => {
return {
navigation: {
shown: false,
width: 550,
borderSize: 3
}
};
},
computed: {
direction() {
return this.navigation.shown === false ? "Open" : "Closed";
}
},
methods: {
setBorderWidth() {
let i = this.$refs.drawer.$el.querySelector(
".v-navigation-drawer__border"
);
i.style.width = this.navigation.borderSize + "px";
i.style.cursor = "ew-resize";
},
setEvents() {
const minSize = this.navigation.borderSize;
const el = this.$refs.drawer.$el;
const drawerBorder = el.querySelector(".v-navigation-drawer__border");
const vm = this;
const direction = el.classList.contains("v-navigation-drawer--right")
? "right"
: "left";
function resize(e) {
document.body.style.cursor = "ew-resize";
let f = direction === "right"
? document.body.scrollWidth - e.clientX
: e.clientX;
el.style.width = parseInt(f) + "px";
}
drawerBorder.addEventListener(
"mousedown",
function(e) {
if (e.offsetX < minSize) {
el.style.transition = "initial";
document.addEventListener("mousemove", resize, false);
}
},
false
);
document.addEventListener(
"mouseup",
function() {
el.style.transition = "";
vm.navigation.width = el.style.width;
document.body.style.cursor = "";
document.removeEventListener("mousemove", resize, false);
},
false
);
}
},
mounted() {
this.setBorderWidth();
this.setEvents();
}
});
,因为您已经在结构化的字典full_list
中拥有总裁的姓名和相应的PIN,因此您可以简单地遍历并将给定的总裁姓名与用户输入进行比较,并在匹配时输出PIN:
roster_snapshot