在LINQ.js查询中传递变量

Passing a variable inside a LINQ.js query

本文关键字:变量 查询 LINQ js      更新时间:2023-10-09

我正在尝试查询存储在data.JSON文件中的JSON数据。当我在linq查询中给出静态值时,我成功地得到了所需的结果,但当用户从下拉菜单中选择值后我传递变量时,linq查询不取其动态值。这是我的静态值工作代码。

$("#community").change(function() {
    $.ajax({
        url: 'json/data.json',
        type: 'get',
        dataType: 'json',
        success: function(searchres) {
            //console.log(searchres);   
            /////////////////////////////assigning searched results to handlebar.js
            var community = $('#community').val();
            var queryResult = Enumerable.From(searchres)
                .Where("$.kls_commId = 7 ")
                .ToArray();
            console.log(queryResult);
            //var bb = Handlebars.compile($('#beds').html());
            //  $('.mybeds').append(bb(responseBeds));
            /////////////////////////////assigning searched results to handlebar.js
        }
    });
});

现在我必须在where子句中传递select框值,我尝试过Where("$.kls_commId = community ")Where("$.kls_commId = $('#community').val() "),但不起作用。

得到了答案。我不得不使用Where("$.kls_conmmId="+community)

我是jinqJs 的作者

使用jinqJs,您可以通过以下操作访问外部变量:

var nm="Tom";

result=jinqJs().来自(数据1).其中('Name=='+nm).select(谓词);