我有一个JSON字符串,并被绑定到一个javascript对象
{
"results":[
{
"id":"460",
"name":"Widget 1",
"loc":"Shed"
},{
"id":"461",
"name":"Widget 2",
"loc":"Kitchen"
}]
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在javascript中"查询"这个数据,所以我可以搜索ID为460并返回名称和loc(除了循环整个对象)?我有jQuery和Prototypejs可供使用.
我最近开始使用 taffydb。假设我有这个作为我的数据
db= TAFFY([
{OrderNo:'prod1',range: 3,description:'one two'},
{OrderNo:'prod2',range: 2,description:'one two three'},
{OrderNo:'prod3',range: 2,description:'one three two'},
{OrderNo:'prod4',range: 6,description:'one two four three'},
{OrderNo:'prod5',range: 5,description:'three'},...
Run Code Online (Sandbox Code Playgroud)
如果我想编写一个查询来查找包含“一二”和“三”的所有记录,我会这样做
db({description:{likenocase:"one two"}},{description:{likenocase:"three"}}).get()
Run Code Online (Sandbox Code Playgroud)
这将返回产品 2 和 4。不幸的是,我不知道如何使用动态查询来执行此操作,该查询将要搜索未知数量的变量。我这样做是为了让用户搜索他们自己提供的单词。
有人有什么想法吗?
我本周刚刚开始学习淘汰赛,除了这一个问题外,一切都进展顺利.
我有一个项目列表,我按多种方式排序,但我想要排序的方式之一需要有一个不同于标准列表的显示.举个例子,假设我有这个代码
var BetterListModel = function () {
var self = this;
food = [
{
"name":"Apple",
"quantity":"3",
"category":"Fruit",
"cost":"$1",
},{
"name":"Ice Cream",
"quantity":"1",
"category":"Dairy",
"cost":"$6",
},{
"name":"Pear",
"quantity":"2",
"category":"Fruit",
"cost":"$2",
},{
"name":"Beef",
"quantity":"1",
"category":"Meat",
"cost":"$3",
},{
"name":"Milk",
"quantity":"5",
"category":"Dairy",
"cost":"$4",
}];
self.allItems = ko.observableArray(food); // Initial items
// Initial sort
self.sortMe = ko.observable("name");
ko.utils.compareItems = function (l, r) {
if (self.sortMe() =="cost"){
return l.cost > r.cost ? 1 : -1
} else if (self.sortMe() =="category"){
return l.category > r.category …Run Code Online (Sandbox Code Playgroud)