我对命令模式感到困惑.关于这些命令有很多不同的解释.我认为下面的代码是委托命令,但在阅读了关于relaycommand后,我有点怀疑.
relay命令,delegatecommand和routedcommand之间的区别是什么.是否可以在与我发布的代码相关的示例中显示?
class FindProductCommand : ICommand
{
ProductViewModel _avm;
public FindProductCommand(ProductViewModel avm)
{
_avm = avm;
}
public bool CanExecute(object parameter)
{
return _avm.CanFindProduct();
}
public void Execute(object parameter)
{
_avm.FindProduct();
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
Run Code Online (Sandbox Code Playgroud) 我无法阅读我的 DTO 列表。
我希望从数据库接收 DTO 列表,以便我可以将它们放在 WPF 部分的表中,但是当我运行程序时,列表中没有数据,也没有错误。我不明白为什么,我的代码有问题吗?
public IList<ProductDTO> GetProducts()
{
IList<ProductDTO>listofproducts = new List<ProductDTO>();
ProductDTO productDto = new ProductDTO();
using (var db = new NORTHWNDEntities())
{
var query = from p in db.Products
select new
{
Name = p.ProductName,
};
foreach (var product in query)
{
productDto.Name = product.Name;
listofproducts.Add(productDto);
}
return listofproducts;
}
}
Run Code Online (Sandbox Code Playgroud)
更新后的版本:
我在代码末尾收到一个名为 entityexception 的错误,由用户代码未处理(tolist)
public IEnumerable<ProductDTO> GetProducts()
{
using (var db = new NORTHWNDEntities())
{
return db.Products.Select(m => new ProductDTO { Name = …Run Code Online (Sandbox Code Playgroud) 我如何在多个表中搜索?我有这个代码,但这只适用于我的一个表.我总共有4张桌子.
这是我的表格中"某事"之后的搜索代码.
$(document).ready(function() {
$('#search').keyup(function() {
searchTable($(this).val());
});
});
function searchTable(inputVal) {
var table = $('#searchTable');
table.find('tr').each(function(index, row) {
var allCells = $(row).find('td');
if(allCells.length > 0) {
var found = false;
allCells.each(function(index, td) {
var regExp = new RegExp(inputVal, 'i');
if(regExp.test($(td).text())) {
found = true;
return false;
}
});
if(found == true) $(row).show();
else $(row).hide();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我已经剥离了我的表格代码,以便它看起来更易于管理
问题在于"搜索tabe"只运行表1而不是剩余的表
表格1:
<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud)
表2:
<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud)
表3:
<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud)
表4:
<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud) 我从另一个页面获取一个名为小计的值.我想清理价值.但它不会工作.它没有返回任何值.
if (isset($_GET['subtotal']))
{
$sub = htmlentities($_GET['subtotal']);
echo cleanData($sub);
}
function cleanData($data)
{
$data=trim();
$data=stripcslashes();
$data=htmlspecialchars();
$data=strip_tags();
return $data;
}
Run Code Online (Sandbox Code Playgroud)