为了在页面刷新时保持状态,我正在尝试集成redux-persist. 但是,它不起作用。页面刷新会清除状态。以下是_persistobject int the state 的样子:
_persist: {
version: -1,
rehydrated: true
}
Run Code Online (Sandbox Code Playgroud)
这是configureStore.js:
import { createStore, applyMiddleware, compose } from "redux";
import logger from "redux-logger";
import thunk from "redux-thunk";
import rootReducer from "./_reducers/rootReducer";
import storage from "redux-persist/lib/storage";
import { persistStore, persistReducer } from "redux-persist";
const persistConfig = {
key: "root",
storage,
whitelist: []
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
const middlewares = [thunk];
// if (__DEV__) react native check dev
middlewares.push(logger);
const store = createStore( …Run Code Online (Sandbox Code Playgroud) 我有以下代码,我需要根据条件将新项目添加到导航属性中。类的NotificationToUser属性Notification是IEnumerable类型。
Notification notification = new Notification
{
DateCreated = DateTime.Now,
ToUsers = _context.PeerGroupMemberships
.Where(pg => pg.PeerGroup.SubmissionId == assessmentItem.SubmissionId && pg.UserId != currentUser.Id)
.Select(pg => new NotificationToUser { IsRead = false, UserId = pg.UserId })
};
if(submissionOwnerId != currentUser.Id)
{
notification.ToUsers = notification.ToUsers.Append(new NotificationToUser { IsRead = false, UserId = submissionOwnerId });
}
_context.Notifications.Add(notification);
_context.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
但是,向导航属性添加新项目会导致此错误:
System.InvalidOperationException: '实体类型'通知'上的导航属性'ToUsers'的类型是'AppendPrepend1Iterator',它没有实现ICollection。集合导航属性必须实现目标类型的 ICollection<>。
通知类是:
public class Notification
{
[Key]
public int Id { get; set; }
public string Text …Run Code Online (Sandbox Code Playgroud) 我正在使用react-google-login库让用户通过谷歌在客户端登录我的应用程序,它工作正常并返回令牌和个人资料信息。
<GoogleLogin
clientId="XXXX.apps.googleusercontent.com"
buttonText="Login"
onSuccess={responseGoogle}
onFailure={responseGoogle}
cookiePolicy={'single_host_origin'}
/>
const responseGoogle = (response) => {
console.log(response);
}
Run Code Online (Sandbox Code Playgroud)
以下是启用 Google 身份验证的服务器上的配置:
services.AddAuthentication()
.AddGoogle(options =>
{
IConfigurationSection googleAuthNSection =
Configuration.GetSection("Authentication:Google");
options.ClientId = googleAuthNSection["ClientId"];
options.ClientSecret = googleAuthNSection["ClientSecret"];
});
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何将这个成功登录转移到asp.net 服务器端。如何使用google发送的token在服务器端登录用户?我想在两种情况下这样做:(a)系统中的电子邮件与 gmail 不匹配,(b)系统中的电子邮件与 gmail 匹配。我很感激任何帮助。
我正在使用 TypeScript 开发 React 应用程序。我有以下简单的发布方法:
import React, { useState } from 'react';
import axios from 'axios';
await axios.post('api/account/register', {
FirstName: formData.firstName,
LastName: formData.lastName,
Username: formData.email,
Password: formData.password,
IsLocked: true,
Role: 'Admin',
});
Run Code Online (Sandbox Code Playgroud)
下面是js文件中的相应代码:
const axios_1 = __importDefault(require("axios"));
const react_1 = __importStar(require("react"));
yield axios_1.default.post('api/account/register', {
FirstName: formData.firstName,
LastName: formData.lastName,
Username: formData.email,
Password: formData.password,
IsLocked: true,
Role: 'Admin',
});
Run Code Online (Sandbox Code Playgroud)
它抛出此异常:axios_1.default.post is not a function error。我安装了最新版本的 axios。
以下是ts.config文件:
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"jsx": "react",
"skipLibCheck": true, …Run Code Online (Sandbox Code Playgroud) 我有以下从 IdentityUser 派生的类。Person 类存储在数据库的 AspNetUsers 表中,并且在数据库端一切看起来都很好。
public class Person : IdentityUser
{
[Required]
[StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
public string FirstName { get; set; }
[Required]
[StringLength(150, ErrorMessage = "Last name cannot be longer than 150 characters.")]
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的问题是关于创建一个具有名字和姓氏的新用户(人)。我想,首先我需要这样做:
var user = new IdentityUser() { UserName = "testing" };
IdentityResult result = userManager.Create(user,"123456");
Run Code Online (Sandbox Code Playgroud)
这将向 AspNetUsers 表插入一个新行,其中名字和姓氏字段为空。然后,通过使用 LinQ,我需要更新现有记录的名字和姓氏字段。这种做法合理吗?还有其他推荐的方法吗?
c# linq entity-framework entity-framework-6 asp.net-identity
我一直在尝试将页面滚动到div由ajax调用创建的动态.
当#divnotifications div点击(如下图),我做的第一个Ajax调用,增加的Post详细信息,然后在此Ajax调用,另一个AJAX调用,以相关的注释添加到div.
到目前为止解释的部分很有用.然后,我用$.when().then()滚动到基于ajax调用创建的div项.但是,页面不会滚动到由LoadCommentsForPostajax调用创建的元素.
我有$.when().then()错误的逻辑吗?
$(document).on('click', '#divnotifications div', function (event) {
event.preventDefault();
$.ajax({
//other details
success: function (postid) {
$.when(DisplayPostWithFullDetails(postid)).then(function () {
//scroll to the content created by
//LoadCommentsForPost function nested
//inside DisplayPostWithFullDetails
});
}
});
});
function DisplayPostWithFullDetails(postId) {
$.ajax({
//other details
success: function (post) {
//The code to build the div to display the post -- working fine
LoadCommentsForPost(post.PostId);
}
});
}
function LoadCommentsForPost(postid) {
$.ajax({ …Run Code Online (Sandbox Code Playgroud) 我在 Scikit-Learn 中使用 Logistic 回归模型(特别是LogisticRegressionCV)。当我使用默认tol值(即1e-4)并用不同的random_state值测试模型时,特征系数波动不大。至少,我可以看到哪些功能是重要的。
然而,当我设置较高的tol值(例如2.3)时,每次运行模型时,特征系数都会大幅波动。当在一次试验中特征 A 的系数为 -0.9 时,在下一次试验中它可能为 0.4。
这让我认为正确(或有利)的tol值应该是结果更加一致的值。
以下是我的代码的相关部分:
classifier = LogisticRegressionCV(penalty='l1', class_weight='balanced',
#tol=2.2,
solver='liblinear')
Run Code Online (Sandbox Code Playgroud)
我想知道是否有指南可以确定适当的tol值。
我正在学习用于自动分组用户的优化算法.但是,我对这些算法完全陌生,我在回顾相关文献时听说过它们.而且,不同的是,在其中一篇文章中,作者使用整数编程实现了他们自己的算法(基于他们自己的逻辑)(这就是我所知道的IP).
我想知道是否需要使用混合整数线性编程实现遗传/粒子群(或任何其他优化)算法,或者这只是其中一个选项.最后,我需要构建一个基于Web的系统,自动对用户进行分组.我感谢任何帮助.
optimization linear-programming genetic-algorithm particle-swarm integer-programming
我试图在熊猫数据帧的尾部得到1的计数.从这个数据框:
x
1
2
3
1
1
1
Run Code Online (Sandbox Code Playgroud)
我想得到3的数.如果尾部没有1,那么函数应该返回0.我找不到任何pandas函数来执行此操作.有任何想法吗?
我有一个类似于的数据框:
col1 col2
1 10
1 30
2 60
3 20
3 12
3 51
3 11
Run Code Online (Sandbox Code Playgroud)
当col2中的值大于50时,我想将此数据帧划分为多个通道:
dataframe #1
col1 col2
1 10
1 30
2 60
dataframe #2
col1 col2
3 20
3 12
3 51
dataframe #3
col1 col2
3 11
Run Code Online (Sandbox Code Playgroud)
我已尝试过split功能,但它无法完成此任务.我想知道是否有通用功能来实现这一目标?
我正在尝试将Redux集成到现有的React应用程序中。我正在学习redux。我正在使用挂钩。互联网上有许多使用类组件的示例。我找不到如何使用功能组件实现此目的的示例。
下面的代码不会引发错误。但是,内部的动作useEffect没有被调用。该代码不产生任何输出。我想知道电话是否正确。有什么帮助吗?
Index.js
const store = createStore(rubricReducer, applyMiddleware(thunk));
ReactDOM.render(
<BrowserRouter basename={baseUrl}>
<Provider store={store} > <App /> </Provider>
</BrowserRouter>,
rootElement);
Run Code Online (Sandbox Code Playgroud)
Rubrics.tsx
const mapStateToProps = state => ({
rubrics: state.rubrics.items,
loading: state.rubrics.loading,
error: state.rubrics.error
});
const mapDispatchToProps = (dispatch) => {
return {
getRubrics: () => dispatch(fetchRubrics())
};
}
const Rubrics = (props) => {
const { rubrics, loading, error } = props;
useEffect(() => {
props.dispatch(fetchRubrics());
}, []);
if (error) { return <div>Error! {error.message}</div>; }
if (loading) { return …Run Code Online (Sandbox Code Playgroud) 我有以下简单的代码使用该CreateAsync方法创建新用户。该代码不会引发任何错误,但是也不会更新数据库。我在该IdentityResult result行的断点处添加了一个断点,并在if语句中的断点处添加了一个断点。结果,我不知道如何调试此代码并查找错误。有什么帮助吗?
public async Task<IdentityResult> Create(ApplicationUser user, string password)
{
IdentityResult result = await _userManager.CreateAsync(user, password);
if (!result.Succeeded)
{
throw new AppException("Failed");
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
Create从控制器调用此函数:
[AllowAnonymous]
[HttpPost]
[Route("api/ApplicationUser/Register")]
public IActionResult Register([FromBody]ApplicationUserDto userDto)
{
//map dto to entity
var user = _mapper.Map<ApplicationUser>(userDto);
try
{
// save
_userService.Create(user, userDto.Password);
return Ok();
}
catch (AppException ex)
{
// return error message if there was an exception
return BadRequest(new { message = ex.Message });
} …Run Code Online (Sandbox Code Playgroud) reactjs ×4
asp.net ×3
c# ×3
asp.net-core ×2
dataframe ×2
javascript ×2
redux ×2
ajax ×1
async-await ×1
axios ×1
jquery ×1
linq ×1
oauth-2.0 ×1
optimization ×1
pandas ×1
python ×1
r ×1
react-hooks ×1
react-redux ×1
scikit-learn ×1
typescript ×1