我将2个值传递给子组件:
我使用.map()函数来显示我的对象列表(如反应教程页面中给出的示例),但该组件中的按钮在渲染时触发onClick函数(在渲染时不应触发).我的代码看起来像这样:
module.exports = React.createClass({
render: function(){
var taskNodes = this.props.todoTasks.map(function(todo){
return (
<div>
{todo.task}
<button type="submit" onClick={this.props.removeTaskFunction(todo)}>Submit</button>
</div>
);
}, this);
return (
<div className="todo-task-list">
{taskNodes}
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么我的onClick函数会在渲染上触发,以及如何使它不成功.
为什么C#中的属性不能只读?
当我尝试只读一个属性时,它表明:
修饰符'readonly'对此项无效
在这里问了Simmilar的问题: 为什么属性不能只读? 但问题是在5年前提出的,然后提供的答案是:因为他们没有想到它.5年后仍然如此吗?
编辑:代码示例:
public class GreetingClass
{
public readonly string HelloText { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我在 echarts (v4.0.4) 中遇到的问题是,我无法更改图标上的图例悬停颜色以匹配我使用series[].empahsis.itemStyle.color提供的条形图悬停颜色。
查看 echarts legend api,我没有找到一个属性可以让我指定图例图标悬停时的颜色。
有关更清晰的示例,请参阅下面的图片。我已经突出显示了有问题的区域(图一是图表,图二是当我将图例悬停在 Total clients 上时。您可以看到图标颜色与条形强调颜色不匹配。条形图很暗,但图例图标几乎没有可见的)
下面我提供了我传递给 echarts 的选项 json。
const options = {
legend: {
show: true,
data: [
{
name: LANG.clientRetention
},
{
name: LANG.totalClients
}
]
},
series: [
{
name: LANG.clientRetention,
type: "line",
symbolSize: 7,
lineStyle: {
width: 3,
color: style.lineColor
},
itemStyle: {
color: style.lineColor,
borderWidth: 3,
opacity: 1
},
data: this.getRettention() //this returns a string array
},
{
name: LANG.totalClients,
type: "bar",
data: this.getTotalClients(), // …Run Code Online (Sandbox Code Playgroud) 我有一个自定义ExceptionFilter,它记录Web-Api控制器中所有未捕获的异常.我想使用Autofac,为它注入ILog配置.
我的问题是怎么做?Autofac网站几乎没有解释如何这样做.
CustomFilter:
public class ApiControllerErrorFilterAttribute : ExceptionFilterAttribute
{
private static readonly ILog log = LogManager.GetLogger("ApiLog");
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
log.Error("Error: ", actionExecutedContext.Exception);
}
}
Run Code Online (Sandbox Code Playgroud)
ps为了澄清,我还有一个普通控制器的自定义过滤器,我能够成功配置它.
过滤正常控制器:
public class ControllerErrorFilterAttribute : HandleErrorAttribute
{
public ICustomLogSettings Log { get; set; }
public override void OnException(ExceptionContext filterContext)
{
Log.GetLogger.Error("Error: ", filterContext.Exception);
}
}
Run Code Online (Sandbox Code Playgroud)
日志配置:
builder.Register(c => new BaseLog()).As<ICustomLogSettings>().InstancePerRequest();
builder.RegisterFilterProvider();
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我使用XML来导入类的各种实例.我需要在List中导入.问题是如何在Dictionary中导入所有"dynamicDrop":
XML:
<LootProfile name="volpeNormale">
<dynamicDropNumber>3</dynamicDropNumber>
<dynamicDrop>70</dynamicDrop>
<dynamicDrop>40</dynamicDrop>
<dynamicDrop>10</dynamicDrop>
<dynamicTypeArmor>33</dynamicTypeArmor>
<dynamicTypeWeapon>33</dynamicTypeWeapon>
<dynamicTypeConsumable>34</dynamicTypeConsumable>
<dynamicRarityCommon>70</dynamicRarityCommon>
<dynamicRarityUncommon>20</dynamicRarityUncommon>
<dynamicRarityRare>8</dynamicRarityRare>
<dynamicRarityEpic>2</dynamicRarityEpic>
<staticDropNumber>2</staticDropNumber>
<staticDrop idPattern="100">60</staticDrop>
<staticDrop idPattern="145">100</staticDrop>
<faction>All</faction>
<location>All</location>
</LootProfile>
Run Code Online (Sandbox Code Playgroud)
XMLImporter查询:
var query = from item in xml.Root.Elements("LootProfile")
select new LootProfile()
{
name = (string)item.Attribute("name"),
dynamicDropNumber = (int)item.Element("dynamicDropNumber"),
dynamicDrop = (Dictionary<int,string>)item.Element("dynamicDrop) //this one doesnt work!
//other element....
}
return query.ToList<LootProfile>();
Run Code Online (Sandbox Code Playgroud) 假设我有一张桌子
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Order Dat</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cakes</td>
<td>100 $</td>
<td>2015-01-09</td>
</tr>
<tr>
<td>Clouthing for Sping</td>
<td>20000 $</td>
<td>2015-02-09</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我希望第二列(价格)是其标题长度的确切大小或该列中最长的内容长度。我不希望第二列具有浏览器添加到该列中的“不可见空白”,以使表更宽。
我已经尝试过的:
设置默认%或px宽度。这不适合我,因为我不知道我的数据会持续多久。
将表格宽度设置为不等于100%。这就是原因,导致表拉伸并将那些“空白”添加到我的列中。问题是我需要我的表是100%,我只希望其中一列不被拉伸。
附言:我也在使用引导程序。(不知道是否有帮助)
编辑:
图片:
假设我有一个基类:
public class Base{
}
Run Code Online (Sandbox Code Playgroud)
我有一个继承自Base Class的类Derived:
public class Derived: Base{
}
Run Code Online (Sandbox Code Playgroud)
是否有可能为List<T>类继承一个只从Base类继承的扩展方法,如下所示:
public static string F(this List<Base> baseClass){
return "This class inherits from Base Class";
}
Run Code Online (Sandbox Code Playgroud)
扩展方法应该适用于List<Base>和List<Derived>.但它不适合我.
在ASP.NET MVC 5中,在控制器中,我已经使用已发出请求的用户:
ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
Run Code Online (Sandbox Code Playgroud)
使用ApplicationUser实例,我如何获得用户的所有角色?
c# ×4
asp.net-mvc ×2
javascript ×2
.net ×1
autofac ×1
css ×1
echarts ×1
html ×1
inheritance ×1
linq ×1
owin ×1
reactjs ×1