我只想等待一个进程完成,不想让函数异步.
请参阅以下代码.
我不得不使getUserList异步,因为函数中有一个await关键字.因此,我还必须编写"await UsersService.getUserList"来执行该方法,并且我必须使父函数异步.那不是我想要做的.
import xr from 'xr' //a package for http requests
class UsersService {
static async getUserList() {
const res = await xr.get('http://localhost/api/users')
return res.data
}
}
export default UsersService
Run Code Online (Sandbox Code Playgroud)
import UsersService from './UsersService'
class SomeClass {
async someFunction() { //async again!!
const users = await UsersService.getUserList() //await again!!
}
}
Run Code Online (Sandbox Code Playgroud) 我想使用ajax渲染局部视图.
提交按钮时,必须呈现局部视图.
我可以使用ActionLink实现它,但我想通过JavaScript调用Action.
但是以下代码不起作用.调用Action但不呈现局部视图.
视图
@section script{
<script type="text/javascript">
function test() {
$.ajax(
{
type: "POST",
url: "Test",
data: "",
success: function (result) { alert("OK!!"); },
error: function (req, status, error) {
alert("Damn!!");}
});
}
</script>
}
<input type="submit" onclick="test()" />
<div id="Container">
Run Code Online (Sandbox Code Playgroud)
调节器
public ActionResult Test()
{
if (Request.IsAjaxRequest())
{
return PartialView("ViewUserControl1");
}
return View();
}
Run Code Online (Sandbox Code Playgroud)
部分视图ViewUserControl1
Hello world
Run Code Online (Sandbox Code Playgroud)
这有效,但不是我想做的
@Ajax.ActionLink("click me", "Test", new AjaxOptions { UpdateTargetId = "Container" })
Run Code Online (Sandbox Code Playgroud) 我发现至少有两种方法可以在实体中创建记录,如下所示.
共同部分
var record = new someEntity()
{
attribute1="test1",
attribute2="test2"
};
var service = new OrganizationService("CrmConnectionString");
Run Code Online (Sandbox Code Playgroud)
A部分
service.Create(record);
Run Code Online (Sandbox Code Playgroud)
B部分
var orgContext = new OrganizationServiceContext(service);
orgContext.AddObject(record);
orgContext.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
有什么区别?哪个更好?
我正在考虑使用dart开发一个Web应用程序.
Dartium上的行为和Chrome上的行为(使用编译的JavaScript)之间是否存在差异?
我认为我应该在Dartium上发展,因为可调试但我担心行为可能存在差异.
用户.js
class User {
constructor() {
this.fisrtName
this.lastName
}
get fullName() {
`${this.firtName} ${this.lastName}`
}
}
export default User
Run Code Online (Sandbox Code Playgroud)
测试.js
import React from 'react'
import {User} from './User'
class Test extends React.Component {
testClick(e) {
const user = new User() //error! because User is undefined.
}
render() {
return (
<button onClick={this.testClick.bind(this)}>test</button>
)
}
}
export default Test
Run Code Online (Sandbox Code Playgroud) 下面的代码片段工作正常.
在这种情况下,"int32"是什么?一个功能?
我知道有一个名为"int32"的类型
这可能是一个愚蠢的问题.我刚刚完成了A Tour of Go但我找不到答案.(我可能会遗漏一些东西.)
package main
import "fmt"
func main() {
var number = int32(5)
fmt.Println(number) //5
}
Run Code Online (Sandbox Code Playgroud) 我想我也可以在FloatProperty或ListProperty中存储纬度/经度数据.
我想我明白指针是什么,但我不太明白何时使用它.
以下片段来自"A Tour of Go".
"*Vertex"和"&Vertex"的目的是什么?
我用"顶点"替换它们,它运行正常.
package main
import (
"fmt"
"math"
)
type Vertex struct {
X, Y float64
}
func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func main() {
v := &Vertex{3, 4}
fmt.Println(v.Abs())
}
Run Code Online (Sandbox Code Playgroud) var obj = {'test1':"value1", "test2": "value2" }
console.log(obj);
Run Code Online (Sandbox Code Playgroud)
reuslt
[object, Object]
Run Code Online (Sandbox Code Playgroud)
是否有可能在IE9上显示对象不使用JSON.stringify的内容?
如下
{'test1':"value1", "test2": "value2" }
Run Code Online (Sandbox Code Playgroud) 我创建了一个名为"memory-box"的自定义元素,如下面的代码所示.
请注意"memory-box-template"中的"logthis"功能.
内存box.html
<template id="memory-box-template">
<input id="memory-box" type="form" />
<input type="button" id="testbutton" />
<script type="text/javascript">
function logthis(me){
console.log(me);
}
</script>
</template>
<script type="text/javascript">
(function() {
var thisDoc = document.currentScript.ownerDocument;
var storage = localStorage;
var proto = Object.create(HTMLElement.prototype, {
createdCallback: {
value: function() {
var temp = thisDoc.querySelector('#memory-box-template');
var con = document.importNode(temp.content, true);
this.createShadowRoot().appendChild(con);
var input = this.querySelector('::shadow #memory-box');
var data = storage.getItem(this.id);
input.value = data;
input.addEventListener('input', saveData.bind(input, this.id));
}
},
});
document.registerElement('memory-box', {
prototype: proto
});
function saveData(id, e) { …Run Code Online (Sandbox Code Playgroud) 这不是来自文件,但这是一个变量的值,如下所示:
fulltext = u'''test1,TEST1
test2,TEST2'''
Run Code Online (Sandbox Code Playgroud) 我有以下项目:
CompanyName.SystemName.ProjectName
Run Code Online (Sandbox Code Playgroud)
与Using它一起使用时看起来像命名空间,但事实并非如此.
我一直以为我应该在单击提交按钮时验证JavaScript上的表单数据,之后我应该验证在服务器端C#上提交的数据.
但是现在我想我可能不需要在JavaScript上验证表单数据?因为Ajax无论如何都不会重新加载页面,这意味着来自JavaScript的错误消息和来自C#的错误消息之间的用户没有区别.
奇怪的想法?
javascript ×4
c# ×3
go ×2
.net ×1
async-await ×1
babeljs ×1
dart ×1
dynamics-crm ×1
ecmascript-6 ×1
jquery ×1
pointers ×1
python ×1
reactjs ×1
shadow-dom ×1