我知道jquery将允许您使用.attr()方法修改属性.基本上有两种方法:
$('#element').attr('attribute', 'value') // sets the attribute
var attribute = $('#element').attr('attribute') // gets the attribute
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何设置一个布尔属性,例如复选框上的'checked'或select标签上的'multiple'?
我尝试过以下操作但没有成功:
$('#element').attr('attribute', true)
$('#element').attr('attribute', '')
Run Code Online (Sandbox Code Playgroud)
所有这些都添加了属性,但通常是这样的<tag attribute="attribute">.
我有一个使用IOC和DI来创建和注入服务的应用程序.
我有一个服务层来处理一些业务逻辑,在服务层我有一个与数据库通信的存储库.该存储库使用的是非线程安全的DataContext.
我想使用后台任务异步运行服务上的一些函数,但是知道这会导致存储库出现问题.因此,我希望为每个创建的后台线程创建存储库.这是如何实现的?我正在使用StructureMap作为IoC.
public class Service : IService
{
IRepository _repository;
public Service(IRepository repository)
{
this._repository = repository;
}
public void DoSomething()
{
// Do Work
_repository.Save();
}
}
public class Controller
{
IService _service;
public Controller(IService service)
{
this._service = service;
}
public Action DoSomethingManyTimes()
{
for(int i =0; i < numberOfTimes; i++)
{
Task.Factory.StartNew(() =>
{
_service.DoSomething();
});
}
}
}
Run Code Online (Sandbox Code Playgroud) c# structuremap multithreading dependency-injection inversion-of-control