是否可以使用该focus()方法聚焦div(或任何其他元素)?
我已将tabIndex设置为div元素:
<div ref="dropdown" tabIndex="1"></div>
Run Code Online (Sandbox Code Playgroud)
当我点击它时,我可以看到它变得集中,但是,我正在尝试像这样动态聚焦元素:
setActive(state) {
ReactDOM.findDOMNode(this.refs.dropdown).focus();
}
Run Code Online (Sandbox Code Playgroud)
或者像这样:
this.refs.dropdown.focus();
Run Code Online (Sandbox Code Playgroud)
但是,当触发事件时,组件不会获得焦点.我怎样才能做到这一点?我可以使用其他(非输入)元素吗?
编辑:
嗯,这似乎有可能做到:https://jsfiddle.net/69z2wepo/54201/
但它不适合我,这是我的完整代码:
class ColorPicker extends React.Component {
constructor(props) {
super(props);
this.state = {
active: false,
value: ""
};
}
selectItem(color) {
this.setState({ value: color, active: false });
}
setActive(state) {
this.setState({ active: state });
this.refs.dropdown.focus();
}
render() {
const { colors, styles, inputName } = this.props;
const pickerClasses = classNames('colorpicker-dropdown', { 'active': this.state.active });
const colorFields = colors.map((color, index) => { …Run Code Online (Sandbox Code Playgroud) 我安装了DirectX SDK June 10,但是当我包含时d3dx9.h,编译器找不到它.
我检查了SDK目录,我也没找到它.
文件丢失:d3dx9.lib,d3dx9.h,dxfile.h.
我正在使用react-apollo构建一个使用GraphQL API的客户端,但是,我非常坚持测试.我想要的是模拟服务器,这样我就可以轻松测试应用程序,而无需进行网络调用.
我发现了一些关于如何模拟服务器的指针:
但是在我的应用测试中如何使用这个模拟服务器以避免命中服务器并没有真正的例子.
我的目标是设置集成测试以声明应用程序实际正在运行:
describe('Profile feature', () => {
beforeAll(() => {
store = setupStore();
app = mount(
<ApolloProvider store={store} client={apolloClient}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</ApolloProvider>
);
});
});
Run Code Online (Sandbox Code Playgroud)
商店正在使用Redux,正在创建客户端,如下所示:
const networkInterface = createNetworkInterface({
uri: process.env.REACT_APP_API_URL
});
export const apolloClient = new ApolloClient({
networkInterface
});
Run Code Online (Sandbox Code Playgroud)
如何在这里使用带有graphql-tools的模拟服务器而不是实际的API?
尝试将映像部署到云运行时出现权限错误:
gcloud beta run deploy endpoints_proxy \
--image="gcr.io/endpoints-release/endpoints-runtime-serverless:1.30.0" \
--allow-unauthenticated
Run Code Online (Sandbox Code Playgroud)
这是错误:
ERROR: (gcloud.beta.run.deploy) User [email-goes-here] does not have permission to access namespace [project-id-goes-here] (or it may not exist): Cloud Run does not have permission to get access tokens for the default compute service account, 1088973916567-compute@developer.gserviceaccount.com. Please give Google Cloud Run Service Agent the permission iam.serviceAccounts.getAccessToken on the default compute service account.
Run Code Online (Sandbox Code Playgroud)
我的帐户具有所有者和编辑器权限,我什至尝试附加 Cloud Run Service Agent 角色。
我还尝试将这些角色添加到错误中列出的“默认计算服务帐户”中,但没有奏效。
我无法理解整个ASP.Net Identity框架,我首先尝试将Identity 1.0集成到现有应用程序中,但我最终得到了2个DbContext类,我的应用程序数据在MyDbContext上,而IdentityDbContext上的Identity用户数据.
我想对我的应用程序数据和身份相关数据使用单个DbContext,我在一个不同的问题上发现我可以像使用DbContext一样使用IdentityDbContext; 但是,我想我错过了一些东西.
我正在使用Identity团队的示例项目
PM> Install-Package Microsoft.AspNet.Identity.Samples -Pre
Run Code Online (Sandbox Code Playgroud)
并尝试将DbSet属性插入ApplicationDbContext
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
static ApplicationDbContext()
{
// Set the database intializer which is run once during application start
// This seeds the database with admin user credentials and admin role
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
}
public virtual DbSet<Student> students { get; set; }
public virtual DbSet<Teachers> teachers { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用ApplicationDbInitializer种子方法来填充这两个表,如下所示: …
我正在尝试在类中使用UserManager,但我收到此错误:
Error activating IUserStore{ApplicationUser}
No matching bindings are available, and the type is not self-bindable.
Run Code Online (Sandbox Code Playgroud)
我正在使用默认的Startup.cs,它为每个请求设置一个实例:
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
Run Code Online (Sandbox Code Playgroud)
我能够得到ApplicationDbContext实例,我相信它是由Owin注入的(这是真的吗?):
public class GenericRepository<T> : IGenericRepository<T> where T : class
{
private ApplicationDbContext context;
public GenericRepository(ApplicationDbContext context)
{
this.context = context;
}
}
Run Code Online (Sandbox Code Playgroud)
但我不能用UserManager做同样的事情(它抛出之前显示的错误):
public class AnunciosService : IAnunciosService
{
private IGenericRepository<Anuncio> _repo;
private ApplicationUserManager _userManager;
public AnunciosService(IRepositorioGenerico<Anuncio> repo, ApplicationUserManager userManager)
{
_repo = repo;
_userManager = userManager;
}
}
Run Code Online (Sandbox Code Playgroud)
控制器像这样使用UserManager:
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
} …Run Code Online (Sandbox Code Playgroud) 所以,我正在尝试在我的应用程序上实现不同类型的用户,首先,假设只有一种用户:
public class ApplicationUser : IdentityUser
{
// Other Properties
public int TeacherID { get; set; }
[ForeignKey("TeacherID ")]
public virtual Teacher Teacher { get; set; }
}
public class Teacher
{
[Key]
public int TeacherID { get; set; }
public int UserID { get; set; }
// Other properties
[ForeignKey("UserID")]
public virtual ApplicationUser User { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这两个实体之间存在一对一的关系,但是如果有多种类型的用户呢?我不能在User实体上拥有那个ForeignKey,我想我的方向是错误的.
我虽然为此使用角色,所以每个角色都有管理员,教师,学生和不同类型的角色,但如果我想为每种角色存储额外的属性会怎样?
public class IdentityUserRole<TKey>
{
public IdentityUserRole();
// Resumen:
// RoleId for the role
public virtual TKey RoleId { …Run Code Online (Sandbox Code Playgroud) 我知道这个问题可能会重复,但是现有的问题都没有指向我没有做的任何事情......
我已经使用无服务器框架部署了一个 API,但是我在使用 CORS 时遇到了问题。
我正在使用 axios 执行 get 请求:
axios.get('https://test.execute-api.us-west-1.amazonaws.com/dev/test?from=2012-01-09T21:40:00Z')
.then(response => {
this.data = response.data;
})
.catch(error => console.log(error))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Access to XMLHttpRequest at 'https://test.execute-api.us-west-1.amazonaws.com/dev/test?from=2012-01-09T21:40:00Z' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
我已经做了什么:
此外,我的 Lambda 函数的响应返回以下标头:
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Headers: map[string]string{
"Access-Control-Allow-Origin": "http://localhost:8080",
"Access-Control-Allow-Credentials": "true",
},
Body: string(jsonEvents),
}, nil
Run Code Online (Sandbox Code Playgroud)
我也尝试设置Access-Control-Allow-Origin为'*'
我的 serverless.yml 文件cors: true …
我正在尝试从当前的Owin上下文中获取DbContext,因此我可以在我的应用程序上使用单个上下文,但是,我得到一个NullReferenceException.
我可以访问UserManager和RoleManager:
private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
Run Code Online (Sandbox Code Playgroud)
他们在Identity示例项目中默认配置了它们的来源:
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
Run Code Online (Sandbox Code Playgroud)
但是试图让上下文直接使用它:
ApplicationDbContext context = HttpContext.GetOwinContext().Get<ApplicationDbContext>();
Run Code Online (Sandbox Code Playgroud)
它总是在我的控制器上返回null.如何从Owin上下文中获取当前的DbContext?
编辑:
我正在创建一个与我的通用存储库一起使用的新上下文
public AdminController()
{
AppContext = new ApplicationDbContext();
this.repoProyects = new GenericRepository<Proyect>(AppContext);
}
Run Code Online (Sandbox Code Playgroud)
但是它创建了一个问题,实体是从多个上下文引用的,所以我试图得到当前的Owin上下文:
public AdminController()
{
this.AppContext = HttpContext.GetOwinContext().Get<ApplicationDbContext>();
this.repoProyects = new GenericRepository<Proyect>(AppContext);
}
Run Code Online (Sandbox Code Playgroud)
HttpContext从这里始终为null,所以我不知道如何让上下文将它传递给我的类.
我在更新数据库时遇到问题,当我应用迁移时出现此错误:
The object 'PK_dbo.CostCenter' is dependent on column 'Id'.
ALTER TABLE DROP COLUMN Id failed because one or more objects access this column.
Run Code Online (Sandbox Code Playgroud)
我只是尝试向该表添加虚拟属性(CostCenter)以便能够获取该数据
[Table("Department")]
public class Department
{
public int Id { get; set; }
public string Code { get; set; }
public virtual IList<Cost> Costs_Department { get; set; }
public virtual CostCenter CostCenter { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是 CostCenter 表
[Table("CostCenter")]
public class CostCenter
{
public int Id { get; set; }
public string Code { get; …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×4
asp.net ×2
apollo ×1
directx ×1
entity-framework-migrations ×1
go ×1
javascript ×1
jestjs ×1
ninject ×1
react-apollo ×1
reactjs ×1
sdk ×1
serverless ×1
sql-server ×1
testing ×1