请在标记为重复之前正确阅读此内容,我向您保证我已经阅读并尝试了每个人在 stackoverflow 和 github 上提出的有关此问题的所有建议。
我的应用程序中有一条路由,如下所示;
<div>
<Header compact={this.state.compact} impersonateUser={this.impersonateUser} users={users} organisations={this.props.organisations} user={user} logOut={this.logout} />
<div className="container">
{user && <Route path="/" component={() => <Routes userRole={user.Role} />} />}
</div>
{this.props.alerts.map((alert) =>
<AlertContainer key={alert.Id} error={alert.Error} messageTitle={alert.Error ? alert.Message : "Alert"} messageBody={alert.Error ? undefined : alert.Message} />)
}
</div>
Run Code Online (Sandbox Code Playgroud)
路由渲染Routes
呈现一个切换用户角色的组件,并根据该角色延迟加载正确的路由组件,该路由组件为主页呈现一个开关。简化后如下所示。
import * as React from 'react';
import LoadingPage from '../../components/sharedPages/loadingPage/LoadingPage';
import * as Loadable from 'react-loadable';
export interface RoutesProps {
userRole: string;
}
const Routes = ({ userRole }) => { …
Run Code Online (Sandbox Code Playgroud) 我需要在ASP.NET MVC Core 2项目中编写一个自定义JsonConverter,以将jQuery POST主体中的JSON数据反序列化,因为它是默认模型绑定。这里最困难的部分是我需要在其中包含多态类型数组的基本类型数组的对象上使用TypeNameHandling。我可以用
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)]
Run Code Online (Sandbox Code Playgroud)
但是围绕此问题的安全性问题对于我的项目是不可接受的。我已经编写了一个自定义JSON转换器,并用以下内容标记了我的对象,但是它似乎没有使用我的自定义转换器(未命中断点)。
[JsonConverter(typeof(ApplicationLoggingConverter))]
Run Code Online (Sandbox Code Playgroud)
完整的相关代码如下。我的ApplicationLoggingModel:
public class ApplicationLoggingModel
{
public Guid ApplicationId { get; set; }
[JsonConverter(typeof(ApplicationLoggingConverter))]
public ModelActionBase[] Changes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器动作:
[HttpPost("Save/{id}")]
public async Task<ActionResult> Save(Guid id, [FromBody]ApplicationLoggingModel model)
{
model.ApplicationId = id;
//nothing yet implemented
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
自定义转换器:
public class ApplicationLoggingConverter : JsonConverter
{
private readonly Type[] _types;
public ApplicationLoggingConverter(params Type[] types)
{
_types = types;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{ …
Run Code Online (Sandbox Code Playgroud) 我正在将netcoreapp 2.1与EF Core 2.1一起使用,并通过数据迁移来更新数据库,但是重命名表时遇到了问题。我在这里的主要问题是一个表(以及以后可能的列)可能会多次使用数据重命名,并且我希望能够重命名它们,同时保持数据完整,但据我看来,这些迁移似乎只涉及保持最新的架构。
此问题类似于使用Entity Framework Core 2.0更改或重命名列名而不会丢失数据,但是由于我的过程是自动化的,因此我需要能够使用dotnet.exe在命令行上使用迁移本身来做到这一点。
为此,我将下面的参数传递给dotnet.exe,构建解决方案,从DLL获取数据库上下文,然后使用下面的代码行进行迁移。
ef migrations add "someMigrationName"
Run Code Online (Sandbox Code Playgroud)
...并更新数据库
var migrator = dbContext.Database.GetService<IMigrator>();
migrator.Migrate();
Run Code Online (Sandbox Code Playgroud)
例如,如果名为“ Courases”的表开始收集数据,我需要能够将其重命名为“ Courses”,而不会影响数据,但是当前,以下是迁移中生成的Up函数。
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Courases");
migrationBuilder.CreateTable(
name: "Courses",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
ConcurrencyCheck = table.Column<byte[]>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Courses", x => x.Id);
});
}
Run Code Online (Sandbox Code Playgroud)
根据我的阅读,似乎没有办法用重命名的表而不是删除并重新创建表来生成迁移,但这似乎很疯狂,有没有办法做到这一点/是否有可以传递给dotnet.exe的标志,错过了吗?
我有一个主要的反应应用程序,其中基于选定的服务,我正在将另一个反应应用程序动态加载到第二个根。我正在加载的第二个应用程序使用下面的 webpack.config 捆绑...
const path = require("path")
const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
const glob = require("glob")
module.exports = {
entry: {
"bundle.js": glob.sync("build/static/?(js|css)/*.?(js|css)").map(f => path.resolve(__dirname, f)),
},
output: {
filename: "build/bundle.min.js"
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
plugins: [new UglifyJsPlugin()],
}
Run Code Online (Sandbox Code Playgroud)
然后通过下面我的 package.json 中修改后的 npm run build 命令在构建过程中调用它。
"build": "npm run build-sass npm run build:react && npm run build:bundle",
"build:react": "react-scripts build",
"build:bundle": "webpack --config webpack.config.js",
"build-sass": "node-sass --precision=5 --indent-type=space --output-style=nested --indent-width=2 src/styles/Site.scss …
Run Code Online (Sandbox Code Playgroud) 这个问题已被问过几次,但没有一个解决方案/文档对我有用。
场景 - 我需要从头开始构建一个数据库,并使用所有代码迁移来编辑它,根据文档,下面的行应该从 DbContext/ModelBuilder 创建数据库。
_dbContext.Database.Migrate();
Run Code Online (Sandbox Code Playgroud)
然而,这只是创建数据库本身而不是任何表。如果我运行下面的命令,
_dbContext.Database.EnsureCreated();
Run Code Online (Sandbox Code Playgroud)
数据库和所有表都已创建,但这不是一个选项,因为我需要进一步编辑迁移。我在 Migrate 行之后直接尝试了下面的代码,但 pendingMigrations 始终为 0。
var pendingMigrations = _dbContext.Database.GetAppliedMigrations().ToList();
if (pendingMigrations.Any())
{
var migrator = _dbContext.Database.GetService<IMigrator>();
foreach (var targetMigration in pendingMigrations)
migrator.Migrate(targetMigration);
}
Run Code Online (Sandbox Code Playgroud)
有什么我在这里想念的吗?Database.Migrate() 不应该同时创建表和数据库吗?
注意 - 在测试中,我在尝试另一种方法之前删除了数据库。
一直在寻找高低,以获得如何做到这一点的答案!我基本上有26个组合框名为comboBox1 - comboBox26,并且想要使用for循环向每个框添加项目,所以我需要将comboBox称为字符串.解释不好,这是我到目前为止的代码;
for (int n = 1; n <= 26; n++)
{
this.["comboBox"].Text.AddRange(new string[]
{"First Item", "second item", "third", "fourth", "fifth"});
}
Run Code Online (Sandbox Code Playgroud)
所以在循环之后,所有26个组合框都应填充该字符串数组.这和我尝试的其他所有东西都会抛出一个错误而且似乎无法找到答案,任何帮助都会很棒!
谢谢
我在尝试将样式应用于兄弟元素时遇到了问题.
.ac_numeric input[type=text][disabled] {
cursor: not-allowed;
}
Run Code Online (Sandbox Code Playgroud)
<div class="ac_numeric">
<input type="text" />
<div class="numericbuttonswrapper">
<div class="numericupbutton"></div>
<div class="numericdownbutton"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这一切都运行正常,当它被禁用时将"不允许"光标应用于我的输入但我还需要在禁用输入时将光标添加到我的div class="numericbuttonswrapper"
.
通过可用的css选择器时我找不到答案,这可能吗?
我在 React 中设计了一个组件,其中包含一个只能设置的输入字段,因此必须是只读的,但无法弄清楚如何测试此输入在 Enzyme 中是否为只读。
我找不到有关 readOnly 属性的任何内容,但有人对Test if an Input is disabled有类似的问题。由此看来我需要使用类似下面的代码的东西。
test('select button select input must be read only', () => {
expect(select.find('div').find('div').find('input').hasAttribute('readOnly', 'true').toBeTruthy();
});
Run Code Online (Sandbox Code Playgroud)
但是,hasAttribute
ShallowWrapper 类型无法识别,并且上面链接中的所有其他方法都无法识别。
只是为了澄清我的输入字段如下。
<input readOnly={true} type="text" placeholder={selectedOption} />
Run Code Online (Sandbox Code Playgroud)
以前有人遇到过这种情况吗?我如何使用 Enzyme 来测试此输入是否为只读?