我有一个像这样的架构
var csData = new Schema({
csgo_number: Number,
last_updated: Number,
items: {type: Object, default: {}}
}, { minimize: false });
Run Code Online (Sandbox Code Playgroud)
由于项目是一个很大的列表,我决定将其设为哈希映射以更快地访问它。
items:{
item1: {
price: 2.00
},
item2:{
price: 1.00
},
item3:{
price: 3.00
}
}
Run Code Online (Sandbox Code Playgroud)
我正在循环浏览一堆 html,当我遇到每个新项目时,我正在解析和存储它。
var item1 = 'awp'
csData.findOne({"csgo_number": 1}, function(err, csgoDB){
csgoDB.items[item1] = {
price: 2.00
}
csgoDB.save(function(err){
if(err){console.log('something went wrong')}
});
});
Run Code Online (Sandbox Code Playgroud)
尽管我没有收到任何错误。我的数据没有保存。这是因为我的新商品没有 _id 吗?我用 _id 尝试过,但仍然没有保存。
我正在使用反应查询,因为它非常强大,但我正在努力尝试在提供程序内的许多组件之间共享我的数据。我想知道这是否是正确的方法。
PostsContext.js
import React, {useState} from 'react';
import { useTemplate } from '../hooks';
export const PostsContext = React.createContext({});
export const PostsProvider = ({ children }) => {
const fetchTemplate = useTemplate(templateId);
const context = {
fetchTemplate,
};
return <PostsContext.Provider value={context}>{children}</PostsContext.Provider>;
};
Run Code Online (Sandbox Code Playgroud)
使用模板.js
import React from 'react';
import { useQuery } from 'react-query'
import { getTemplateApi } from "../api";
export default function useTemplate(templateId) {
return useQuery(["templateId", templateId], () => getTemplateApi(templateId), {
initialData: [],
enabled:false,
});
}
Run Code Online (Sandbox Code Playgroud)
然后是我使用上下文的组件
function Posts () { …Run Code Online (Sandbox Code Playgroud) 我很困惑如何遍历这个数据模型.
$scope.object = [ {person1: {name: 'jon', height: 100}} , {person2: {name: 'joe', height: 200}}, {person3: {name: 'lisa', height: 150}}]
Run Code Online (Sandbox Code Playgroud)
我正在尝试像这样重复
<tr ng-repeat = "person in object[0]">
<td>{{person.name}}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
这当然只会显示'jon'.我怎样才能得到所有人(x).name?我可以将它们命名为all1而不是person1,person2,但我的项目的数据模型不允许这样.能做什么?
谢谢
我正在关注一些在线python教程,我现在两次遇到这个语法错误代码,无法弄清楚是什么问题.
这是我的代码:
import urllib
import re
htmlfile = urllib.urlopen("http://finance.yahoo.com/q?s=AAPL")
htmltext = htmlfile.read()
regex = '<span id="yfs_l84_aapl">(.+?)</span>'
pattern = re.compile(regex)
price = re.findall(pattern, html)
print price
Run Code Online (Sandbox Code Playgroud)
我使用的是Enthought Python Distribution软件包(python版本2.7.3)
这是运行上面脚本时的语法错误.
Traceback (most recent call last):
File "E:\python\scripts\stocks.py", line 4, in <module>
htmlfile = urllib.urlopen("http://finance.yahoo.com/q?s=AAPL")
File "e:\python27\lib\urllib.py", line 86, in urlopen
return opener.open(url)
File "e:\python27\lib\urllib.py", line 207, in open
return getattr(self, name)(url)
File "e:\python27\lib\urllib.py", line 291, in open_http
import httplib
File "e:\python27\lib\httplib.py", line 79, in <module>
import mimetools
File "e:\python27\lib\mimetools.py", line 6, …Run Code Online (Sandbox Code Playgroud) 所以我有时间参与我的一个目标:2014-09-20T22:00:08.856Z
我希望在我的应用程序中显示像Day Day Year,h:mm:ss pm/am.
我试过跟随角度文档并做了这个:
{{mytime | date : 'MMMM d y, h:mm:ss a' : UTC}}
Run Code Online (Sandbox Code Playgroud)
这是一个plnkr.http://plnkr.co/edit/UQV31HY7xebo17j7zAWY?p=info
我想以UTC时区显示它,但它显示太平洋时间...... grrr
我有这样的ng for循环
<template ngFor let-game [ngForOf]="(games)" let-index="index">
<tr>
<td>
<select [(ngModel)]="selectedPrice" class="form-control" name="">
<option *ngFor="let price of prices">{{price}}</option>
</select>
</td>
<td>
</tr>
</template>
Run Code Online (Sandbox Code Playgroud)
显然,更改一个元素的价格会更改所有其他元素的价格。
这是我的意思的一个分支,当您更改一个下拉菜单时,它会更改另一个。 https://plnkr.co/edit/LVViSdlgmY56RnO8mAU4?p=preview
我的问题是:有没有一种方法可以利用模板元素中的索引为每个生成的元素仅绑定一个selectedPrice?因此,当我更改一个下拉值的值时,对于其他所有值都不会更改
我已经尝试过某些语法,例如[(ngModel)] =“ selectedPrice [index]”,但在选择价格时没有达到我想要的含义,selectedPrice [index]实际上并不包含值。我还有其他几种可行的方法,但是它们很笨拙。