我有一个在数组中具有不同值的JSON数组,我不知道如何解析它.这是一个例子:
[
{
"firstname": "John",
"lastname": "Doe",
"age": 30
},
{
"companyName": "Doe enterprise",
"location": "NYC",
"numberOfEmployee": 10
}
]
Run Code Online (Sandbox Code Playgroud)
所以我的JSON是这样的,数组的第一个元素是用户,第二个元素是公司.我有相同的榆树:
type alias User =
{ firsname : String
, lastname : String
, age : Int
}
type alias Company =
{ companyName : String
, location : String
, numberOfEmployee : Int
}
Run Code Online (Sandbox Code Playgroud)
然后:Task.perform FetchFail FetchPass (Http.get decodeData url).
那么我该如何获取User并Company传递我的FetchPass功能呢?有一些东西,Json.Decode.at但它只是对象.有没有办法做这样的事情?
decodeData =
Json.at [0] userDecoder
Json.at [1] companyDecoder
Run Code Online (Sandbox Code Playgroud) 这是我想要做但不起作用的:
mystring = "hello world"
toUpper = ['a', 'e', 'i', 'o', 'u', 'y']
array = list(mystring)
for c in array:
if c in toUpper:
c = c.upper()
print(array)
Run Code Online (Sandbox Code Playgroud)
"e"并且"o"在我的数组中不是大写的.
我有一个update功能,采取postID和标题来更新我的帖子.
我想循环搜索帖子以查找帖子并更新其值.我试过用List.map但我不知道放在哪里.这是我想要的伪代码:
update action model =
case action of
UpdateTitle postID title ->
//something like this:
for post in model.posts :
if post.id == postID then
{ post | title = title }
( model.posts , Effects.none )
Run Code Online (Sandbox Code Playgroud) 我有这个:
\nnewStr := fmt.Sprintf("new price: %d\xe2\x82\xac", newPrice)\nfmt.Println(newStr) // new price: %!d(string=500.00)\xe2\x82\xac\n// except I want: new price: 500,00\xe2\x82\xac\nRun Code Online (Sandbox Code Playgroud)\n如何删除字符串末尾的%!d(和 ,这样它就可以像这样)new price: 500,00\xe2\x82\xac
我可以使用一种格式,strings.Replace但我认为这不是一个好的答案。
我的newPrice是一个浮子。
我很确定这已经被问过,但很难用谷歌搜索这类事情。
\n我尝试根据 props 值计算一个值,如下所示:
interface Props {
task: Task;
}
const totalPrice = computed(() => {
return task.paymentDetail.products
.map(p => p.amount)
.reduce((partialSum, acc) => partialSum + acc, 0);
})
Run Code Online (Sandbox Code Playgroud)
然后在我的模板中,我显示计算值,totalPrice如下所示:{{ totalPrice }}。
我的计算从来不是计算,如果我在里面添加一个console.log,我永远不会输入它。
如何根据 props 计算值?
我有两个这样的列表:
newList = (
(1546, 'John'),
(8794, 'Michael'),
(892416, 'Dave'),
(456789, 'Lucy'),
)
oldList = (
(1546, 'John'),
(8794, 'Michael'),
(892416, 'Dave'),
(246456, 'Alexander')
)
Run Code Online (Sandbox Code Playgroud)
我想要一个比较两个列表的功能.它会是这样的:
def compare(new, old):
print('Alexander is not anymore in the new list !')
print('Lucy is new !')
return newList
Run Code Online (Sandbox Code Playgroud)
我想与每个人的身份比较独特.
编辑:结果将是我的功能比较.它打印出差异.我不知道如何开始
我使用nvm文档安装了node/npm.
curl -o- https: //raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | 庆典
然后我安装它:
nvm安装稳定
然后我必须这样做:
nvm使用节点
npm正在工作,但如果我想在全局安装一个包,它就不起作用.
sudo npm install -g package
我有这个:
sudo:npm:找不到命令
我已经看过很多话题,但我对符号链接或其他类似的东西并不是很了解.我正在使用ubuntu 14.04
我知道这是一个非常基本的问题,但这就是问题所在。我正在关注医生。
我正在使用 mongodb、express 和 node。
我有一个包含用户数据的用户集合。当我访问 url '/' 时,我希望获得所有用户的 json;
var users;
MongoClient.connect("mongodb://localhost:27017/test", function(err, db) {
if(err) { return console.dir(err); }
users = db.collection('users');
});
app.get('/', function (req, res) {
users.find({}, function (err, docs) {
res.send(JSON.stringify(docs));
});
});
Run Code Online (Sandbox Code Playgroud)
但 docs 对象包含很多东西,但不是所有用户。如何获取所有用户?
Readable {
connection: null,
server: null,
disconnectHandler:
{ s: { storedOps: [], storeOptions: [Object], topology: [Object] },
length: [Getter] },
bson: {},
ns: 'test.users',
cmd:
{ find: 'test.users',
limit: 0,
skip: 0,
query: {},
slaveOk: true,
readPreference: …Run Code Online (Sandbox Code Playgroud) 这是我的反应代码的简化版本。我有一个这样的钩子:
const [todo, setTodo] = useState();
Run Code Online (Sandbox Code Playgroud)
我的todo看起来像这样:
todo = {
name: 'Name of my todo list',
date: 2022-09-19',
todos: [
'groceries',
'do the laundry'
]
}
Run Code Online (Sandbox Code Playgroud)
在我的主要组件中,我将待办事项传递给“todos 组件”:
在我的 todos 组件中,我在 props 上有一个循环来显示具有 todos 值的所有输入
{todos.map(t => {
<input
value={t}
onChange={e => {
t = e.target.value
}}
/>
})
Run Code Online (Sandbox Code Playgroud)
但不幸的是它没有更新待办事项。我该怎么做呢?我无法使用 setTodo,因为我位于子组件中,setTodo 管理所有待办事项对象,而我只想更新待办事项列表。我的组件不了解完整的待办事项对象,而只了解待办事项列表。
我看过很多关于它的帖子,但我仍然不明白回调。我得到了这样的函数:
function getData (url) {
request(url, function (error, response, data) {
//...
return data;
}
});
}
var data = getData(url);
// I got undefined because it's not finished
if (data)
...
Run Code Online (Sandbox Code Playgroud)
我如何等待我的函数返回继续。我已经看到很多关于回调和承诺的事情,但在这种情况下如何使用它?例如我看过这篇文章,但我不明白答案。
我正在使用节点js
我使用Ubuntu 15.10和zsh(不知道是否可以提供帮助),
所以我尝试安装django:
pip install django
Downloading/unpacking django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
Run Code Online (Sandbox Code Playgroud)
一切正常。当我这样做pip freeze,我可以看到Django的安装。
然后:
django-admin startproject mysite
但是我遇到了这个问题:
zsh: command not found: django-admin
list ×3
python ×3
elm ×2
javascript ×2
node.js ×2
string ×2
arrays ×1
callback ×1
compare ×1
decode ×1
dictionary ×1
django ×1
express ×1
find ×1
format ×1
go ×1
integer ×1
json ×1
mongodb ×1
npm ×1
nvm ×1
parsing ×1
pip ×1
promise ×1
react-hooks ×1
reactjs ×1
sudo ×1
ubuntu ×1
ubuntu-15.10 ×1
updates ×1
uppercase ×1
vue-props ×1
vuejs3 ×1