在jquery中迭代值 [英] Iterate value in jquery

查看:85
本文介绍了在jquery中迭代值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在我的javascript中,我想迭代这个值。代码是:



Hi All,

In my javascript i want to iterate the value. the code is:

function TicketList()
    {
        var self=this;
        self.sample = ko.observableArray([]);
        self.Getjobs = function () {
            
            $.getJSON("/api/ticket", function (data) {
                $.each(data, function (key, val) {
                        
                        self.sample.push(new Ticket(val.JobID, val.CreatedDateTime,val.JobTitle));
                  
                });


            });
        };
    }





此处示例包含循环时间中的jason数组列表我想检查示例中包含的val。如果包含,则不添加数据,否则将数据添加到样本。



here sample containing a jason array list in looping time i want to check the val is containing in the sample.if containing ,dont add data,otherwise add the data to sample.

推荐答案

.getJSON( < span class =code-string> / api / ticket, function (data){
.getJSON("/api/ticket", function (data) {


。 each(data, function (key,val){

self.sample.push( new Ticket(val.JobID,val.CreatedDateTime,val.JobTitle));

});


});
};
}
.each(data, function (key, val) { self.sample.push(new Ticket(val.JobID, val.CreatedDateTime,val.JobTitle)); }); }); }; }





此处示例包含循环时间中的jason数组列表我想检查示例中包含的val。如果包含,则不添加数据,否则将数据添加到样本。



here sample containing a jason array list in looping time i want to check the val is containing in the sample.if containing ,dont add data,otherwise add the data to sample.


尝试使用 jQuery。 inArray() [ ^ ]。



下面的内容...

Try with jQuery.inArray()[^].

Something like below...
if(jQuery.inArray(val, self.sample) > 0)
{
    // Exists.
}
else
{
    // Don't exist.
}



但是如果 val 存储在数组中,请检查数组中保存的确切内容,然后它可以搜索迪直接,否则只需相应地修改代码。


But check what exactly is saved in array, if the val is stored in array, then it can be searched directly, otherwise just modify the code accordingly.


这篇关于在jquery中迭代值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆