程序设计

专业和发烧友程序员的问答

5
如何定义对象数组?
我在TypeScript中创建对象数组: userTestStatus xxxx = { "0": { "id": 0, "name": "Available" }, "1": { "id": 1, "name": "Ready" }, "2": { "id": 2, "name": "Started" } }; 有人可以告诉我如何正确声明其类型吗?是否可以内联,或者我需要两个定义? 我正在尝试用xxx类型声明代替,以便稍后在TypeScript上使用userTestStatus[3].nammme错误的提示来提醒我。
196 typescript 

29
“ SyntaxError:JSON中位置0处的意外令牌<”
在处理类似于Facebook的内容提要的React应用程序组件中,我遇到了一个错误: Feed.js:94未定义的“ parsererror”“ SyntaxError:JSON中位置0处的意外令牌&lt; 我遇到了一个类似的错误,事实证明这是render函数中HTML的错字,但这里似乎并非如此。 更令人困惑的是,我将代码回滚到了较早的已知工作版本,但仍然出现错误。 Feed.js: import React from 'react'; var ThreadForm = React.createClass({ getInitialState: function () { return {author: '', text: '', included: '', victim: '' } }, handleAuthorChange: function (e) { this.setState({author: e.target.value}) }, handleTextChange: function (e) { this.setState({text: e.target.value}) }, handleIncludedChange: function (e) { this.setState({included: e.target.value}) …


8
如何从批处理文件运行PowerShell脚本
我正在尝试在PowerShell中运行此脚本。我将以下脚本另存为ps.ps1我的桌面。 $query = "SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2" Register-WMIEvent -Query $query -Action { invoke-item "C:\Program Files\abc.exe"} 我已经制作了一个批处理脚本来运行此PowerShell脚本 @echo off Powershell.exe set-executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1 pause 但我收到此错误:

3
如何在C#中创建异步方法?
我读过的每篇博客文章都告诉您如何使用C#使用异步方法,但是出于某些奇怪的原因,请不要解释如何构建自己的异步方法来使用。因此,我现在拥有使用我的方法的这段代码: private async void button1_Click(object sender, EventArgs e) { var now = await CountToAsync(1000); label1.Text = now.ToString(); } 我写的这个方法是CountToAsync: private Task&lt;DateTime&gt; CountToAsync(int num = 1000) { return Task.Factory.StartNew(() =&gt; { for (int i = 0; i &lt; num; i++) { Console.WriteLine("#{0}", i); } }).ContinueWith(x =&gt; DateTime.Now); } 这是使用Task.Factory,是编写异步方法的最佳方法,还是应该以其他方式编写?
196 c#  async-await  c#-5.0 


20
如何更改moment.js的语言?
我正在尝试更改moment.js设置的日期的语言。默认语言是英语,但是我想设置德语。这些是我尝试过的: var now = moment().format("LLL").lang("de"); 它给NaN。 var now = moment("de").format("LLL"); 这甚至没有反应。 var now = moment().format("LLL", "de"); 不变:这仍然会产生英文结果。 这怎么可能?


13
在Laravel Eloquent中使用“ With()”函数获取特定列
我有两个表,User和Post。一个User可以有许多posts,一个post只能属于一个user。 在我的User模型中,我有一个hasMany关系... public function post(){ return $this-&gt;hasmany('post'); } 在我的post模型中,我有一个belongsTo关系... public function user(){ return $this-&gt;belongsTo('user'); } 现在,我想使用来连接这两个表,Eloquent with()但是想要第二个表中的特定列。我知道我可以使用查询生成器,但我不想这样做。 当Post我在模型中写... public function getAllPosts() { return Post::with('user')-&gt;get(); } 它运行以下查询... select * from `posts` select * from `users` where `users`.`id` in (&lt;1&gt;, &lt;2&gt;) 但是我想要的是... select * from `posts` select id,username from `users` where `users`.`id` …

10
替代HTML5的iFrame
我想知道HTML5是否可以替代iFrame。我的意思是,无需使用iFrame,就可以在网页内部注入跨域HTML。
196 html  iframe 

11
返回字符串,不带斜杠
我有两个变量: site1 = "www.somesite.com"; site2 = "www.somesite.com/"; 我想做这样的事情 function someFunction(site) { // If the var has a trailing slash (like site2), // remove it and return the site without the trailing slash return no_trailing_slash_url; } 我该怎么做呢?

16
如何遍历日期范围?
我什至不知道如何在不使用某些可怕的循环/计数器类型解决方案的情况下做到这一点。这是问题所在: 给了我两个日期,一个开始日期和一个结束日期,在指定的时间间隔内,我需要采取一些措施。例如:对于2009年3月3日至2009年3月26日之间的每个日期,我需要在列表中创建一个条目。所以我的输入是: DateTime StartDate = "3/10/2009"; DateTime EndDate = "3/26/2009"; int DayInterval = 3; 而我的输出将是具有以下日期的列表: 3/13/2009 3/16/2009 3/19/2009 3/22/2009 3/25/2009 那么,我该怎么做这样的事情呢?我考虑过使用一个for循环,该循环将在范围内的每一天之间使用一个单独的计数器进行迭代,如下所示: int count = 0; for(int i = 0; i &lt; n; i++) { count++; if(count &gt;= DayInterval) { //take action count = 0; } } 但是似乎还有更好的方法?
196 c#  asp.net  datetime  loops 

9
Angular 2 Hover事件
在新的Angular2框架中,是否有人知道像事件一样进行悬停的正确方法? 在Angular1中有ng-Mouseover,但似乎没有保留。 我已经浏览了文档,却没有发现任何东西。

1
Python“提高”用法
raise和raise fromPython 和有什么不一样? try: raise ValueError except Exception as e: raise IndexError 产生 Traceback (most recent call last): File "tmp.py", line 2, in &lt;module&gt; raise ValueError ValueError During handling of the above exception, another exception occurred: Traceback (most recent call last): File "tmp.py", line 4, in &lt;module&gt; raise IndexError IndexError …

17
如何部分更新MongoDB中的对象,以便新对象将与现有对象重叠/合并
鉴于此文档保存在MongoDB中 { _id : ..., some_key: { param1 : "val1", param2 : "val2", param3 : "val3" } } 对新信息的对象param2,并param3从外面的世界需要保存 var new_info = { param2 : "val2_new", param3 : "val3_new" }; 我想将新字段合并/覆盖在对象的现有状态上,以便不会删除param1 这样做 db.collection.update( { _id:...} , { $set: { some_key : new_info } } 将导致MongoDB完全按照要求执行操作,并将some_key设置为该值。取代旧的。 { _id : ..., some_key: …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.