我正在使用一个jQuery插件,需要一个具有以下结构的JSON对象(我将从数据库中检索值):
{ results: [
{ id: "1", value: "ABC", info: "ABC" },
{ id: "2", value: "JKL", info: "JKL" },
{ id: "3", value: "XYZ", info: "XYZ" }
] }
Run Code Online (Sandbox Code Playgroud)
这是我的班级:
public class results
{
int _id;
string _value;
string _info;
public int id
{
get
{
return _id;
}
set
{
_id = value;
}
}
public string value
{
get
{
return _value;
}
set
{
_value = value;
}
}
public string info
{
get
{
return …Run Code Online (Sandbox Code Playgroud) 例:
var t = $.each(templos_cache, function(f,g){
$.each(g.requer, function(h,j){
if (parseFloat(g.id) == id){
alert(j.nome); // OK, return 'afrodite'.
return j.nome; // wrong, return [Object object].
}
});
return '';
});
Run Code Online (Sandbox Code Playgroud)
看看代码,我们可以看到问题...我可以在一个变量范围内做一个集合,但我认为可以存在一些更优雅的方式来做到这一点.
我有一个案例,当我需要将一个复选框和另一个DOM元素的可见性绑定到我的viewModel的布尔属性的反转时:
<input type="checkbox" data-bind="checked: needsReview"> Not Required
<br>
<div id="Some related text" data-bind="visible: needsReview"> other stuff here </div>
Run Code Online (Sandbox Code Playgroud)
var dataFromSever = { needsReview: true };
var theModel = function (jsonData) {
var self = this;
ko.mapping.fromJS(jsonData, {}, self);
}
ko.applyBindings(new theModel(dataFromSever));
Run Code Online (Sandbox Code Playgroud)
在我的实际数据模型中,我有多个这样的属性,所以我不想创建多个ko.computed()字段.我只想绑定"checked: !needsReview()"或维护同样简单的东西.
如何编写一个查询,如果一个列值不为null,则将该值与查询字符串进行比较,否则不要比较列值.
例如,我有一个tbl1,其中包含programs1和programs2两列,这两列中的值可以为null或带有值.我想说if语句
if programs1 is not null, programs1=@programs and
if programs2 is not null, programs2=@programs
Run Code Online (Sandbox Code Playgroud)
我的查询是这样的:
select * from tbl1 where
(programs1 is not null and programs1=@programs)
and
(program2 is not null and programs2=@programs)
Run Code Online (Sandbox Code Playgroud)
但它没有按我想要的方式工作.如何为此案例编写正确的查询?TIA.