我做了一个 PoC 来查看如何处理动态复选框列表上的更改检测(注意,我事先不知道我有多少个复选框。)我创建了一个 ES6 映射(字典)来跟踪每个复选框的选中状态. 但由于某种原因,我收到以下错误:
A component is changing an uncontrolled input of type checkbox to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component
Run Code Online (Sandbox Code Playgroud)
通常,当我知道表单输入字段的数量时,我会通过状态跟踪它们,但是如何处理这种情况。逻辑工作正常,但我需要摆脱错误。
我的应用程序代码:
import React, { Component } from "react";
import Checkbox from "./checkbox";
class App extends Component {
constructor(props) {
super(props);
this.state = {
checkedItems: new Map()
};
this.handleChange = this.handleChange.bind(this);
}
handleChange = …Run Code Online (Sandbox Code Playgroud) 今天我尝试了新的asp.net核心2.0,但是在使用JSON配置文件时遇到了一些麻烦,我没有注入IConfiguration配置构造函数属性.
在asp.net核心1.1中,我将在StartUp中使用以下代码:
public static IConfigurationRoot Configuration;
Public Startup(IHostingEnvironment env) {
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appSettings.json", optional: false, reloadOnChange: true)
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
并可以从代码访问它,如:
private string _mailTo = Startup.Configuration["mailSettings:mailToAddress"];
Run Code Online (Sandbox Code Playgroud)
然而在Core 2.0中他们改为IConfiguration并且它已经定义了,而且我没有看到任何方式我可以在我的其他类中使用该配置,所以我对如何继续进行有点无能为力.
startupClass:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Mvc.Formatters;
using NLog.Web;
using NLog.Extensions.Logging;
using cityInfoTestApi.Services;
namespace cityInfoTestApi
{
public class Startup
{
public IConfiguration Configuration { get; private set; }
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
Configuration = configuration;
env.ConfigureNLog("nlog.config");
}
public void …Run Code Online (Sandbox Code Playgroud) 我对 python 有点陌生,并尝试创建一个 DTO 来最大限度地减少从我的 api 公开的属性数量。我使用 Azure 表存储来获取记录,然后循环它以创建一个忽略属性的较小对象。虽然在这个过程中的某个地方我得到:“TypeError:'AbbreviatedPackage'对象不可迭代”
在我的主要内容中,我有以下调用:
@app.get("/list/")
def process_results(request: Request, x_api_key: str = Depends(X_API_KEY)):
packageClient = QueryClient(az_connection_string, "appstoredev")
results = packageClient.query_packages_storage("PartitionKey eq 'app'")
return results
Run Code Online (Sandbox Code Playgroud)
query_packages_storage()
def query_packages_storage(self, filter_query):
from azure.data.tables import TableClient
table_client = TableClient.from_connection_string(conn_str=self.connection_string, table_name=self.table_name)
entities = table_client.query_entities(filter_query)
json_entities = []
for entity in entities:
print(entity['ImageUrl'])
filtered_entity = AbbreviatedPackage(
entity['ImageUrl'],
entity['PackageName'],
entity['DisplayName'],
entity['Summary']
)
json_entities.append(filtered_entity)
return json.dumps(json_entities)
Run Code Online (Sandbox Code Playgroud)
缩写包类
class AbbreviatedPackage():
def __init__(self, image_url, package_name, display_name, summary):
self.imageUrl = image_url
self.packageName = package_name
self.displayName = …Run Code Online (Sandbox Code Playgroud) 我正在寻找是否有更简单的方法来实现以下目标:
var filesCount = files.length;
for (var j = 0; j < filesCount; j++) {
if (j < 5) {
vm.groupFiles.push({
"fileName": fileName,
"fileType": fileType,
"lastModifiedTime": lastModifiedTime,
"isContainer": isContainer,
"serverRedirectedUrl": serverRedirectedUrl,
"cleanTitle": cleanTitle,
"extention": extention
});
} else {
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法,但没有用,这让我怀疑是否有可能以简写方法完成它而不会污染我的for循环.
for (var i = 0; i < (filesCount || 4); i++) {
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.干杯!
我试图通过返回除1属性以外的所有值来使数组解析。我以为我可以利用传播,但这包括全部。既然我已经写出了整个对象,那么我担心将来会在数组中添加额外的属性。javascript中是否有任何功能可以让我做到这一点?任何提示将不胜感激!!!
//原始对象
0: {
id: 1
isActive: true
isClassification: false
isEditable: true
isRequired: false
isTeamType: false
name: "Business Unit"
termGroup: {id: 1, name: "Team Classifications", isTenantWide: false, termSets: Array(0)}
termGroupId: 1
termGroupName: "Team Classifications"
terms: (3) [{…}, {…}, {…}]
}
Run Code Online (Sandbox Code Playgroud)
//我的解析代码
// args:
// @return {array} - returns an array containing the termsets only.
getTermSets() {
console.log(this._termSetsWithChilden);
return this._termSetsWithChilden.map(termSet => {
return {
id: termSet.id,
isActive: termSet.isActive,
isClassification: termSet.isClassification,
isEditable: termSet.isEditable,
isRequired: termSet.isRequired,
isTeamType: termSet.isTeamType,
name: termSet.name,
termGroupId: termSet.termGroupId,
termGroupName: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在angular 2中使用样式绑定,但是以某种方式我错过了导致其无法正常工作的部分。目的是使默认文本为灰色,并且当用户单击它时(尚未创建代码),该文本将变为deeppink。但是在测试样式属性时,它似乎不起作用。
import { Component } from "@angular/core"
@Component({
selector: "like",
template: `
<i class="glyphicon glyphicon-heart" [style.color]="color ? 'grey' : 'deeppink'" style="font-size: 100px;"></i>
`
})
export class LikeComponent {
count: number = 10;
color: true;
}
Run Code Online (Sandbox Code Playgroud)