Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过匹配文本将json数据放入数组_Javascript_Jquery_Json - Fatal编程技术网

Javascript 通过匹配文本将json数据放入数组

Javascript 通过匹配文本将json数据放入数组,javascript,jquery,json,Javascript,Jquery,Json,我有json数据 [ ["Fruit","Lychee Magic","Dusk"], ["Veggies","Long Beans","Rampage"], ["Fruit","Mango Aroma Sweet","Dawn"] ] 我有纽扣。按钮文本的第一部分类似于json数据 <button type="button" class="mood">Mango</button> <button type="button" class="mood">Lyc

我有json数据

[
["Fruit","Lychee Magic","Dusk"],
["Veggies","Long Beans","Rampage"],
["Fruit","Mango Aroma Sweet","Dawn"]
]
我有纽扣。按钮文本的第一部分类似于json数据

<button type="button" class="mood">Mango</button>
<button type="button" class="mood">Lychee</button>
例外输出:

butTxArr = ["Fruit","Lychee Magic","Dusk", "Fruit","Mango Aroma Sweet","Dawn"];
像这样的

$("#intoArr").click(function () {
    var butTxArr = [];
    $('.mood').each(function () {
        // trim button text
        var text = $(this).text().replace(/^\s*/g, '').replace(/\s*$/g, '');
        data.forEach(function (row) {
            // see if the row contains the text
            if (row.toString().indexOf(text) !== -1)
                // append to array
                butTxArr = butTxArr.concat(row);
        })
    })
    // we're done!
    console.log(butTxArr)
});
$(文档).ready(函数(){
风险值数据=[
[“水果”、“荔枝魔法”、“黄昏”],
[“蔬菜”、“长豆”、“狂暴”],
[“水果”、“芒果香甜”、“黎明”]
];
$(“#intoArr”)。单击(函数(){
var butTxArr=[];
$('.mood')。每个(函数(){
//修剪按钮文本
var text=$(this.text().replace(/^\s*/g')。replace(/\s*$/g');
data.forEach(函数(行){
//查看该行是否包含文本
if(row.toString().indexOf(text)!=-1)
//附加到数组
butTxArr=butTxArr.concat(行);
})
})
//我们完了!
警报(butTxArr)
});
});

芒果
荔枝
显示类似这样的内容

$("#intoArr").click(function () {
    var butTxArr = [];
    $('.mood').each(function () {
        // trim button text
        var text = $(this).text().replace(/^\s*/g, '').replace(/\s*$/g, '');
        data.forEach(function (row) {
            // see if the row contains the text
            if (row.toString().indexOf(text) !== -1)
                // append to array
                butTxArr = butTxArr.concat(row);
        })
    })
    // we're done!
    console.log(butTxArr)
});
$(文档).ready(函数(){
风险值数据=[
[“水果”、“荔枝魔法”、“黄昏”],
[“蔬菜”、“长豆”、“狂暴”],
[“水果”、“芒果香甜”、“黎明”]
];
$(“#intoArr”)。单击(函数(){
var butTxArr=[];
$('.mood')。每个(函数(){
//修剪按钮文本
var text=$(this.text().replace(/^\s*/g')。replace(/\s*$/g');
data.forEach(函数(行){
//查看该行是否包含文本
if(row.toString().indexOf(text)!=-1)
//附加到数组
butTxArr=butTxArr.concat(行);
})
})
//我们完了!
警报(butTxArr)
});
});

芒果
荔枝
显示类似这样的内容

$("#intoArr").click(function () {
    var butTxArr = [];
    $('.mood').each(function () {
        // trim button text
        var text = $(this).text().replace(/^\s*/g, '').replace(/\s*$/g, '');
        data.forEach(function (row) {
            // see if the row contains the text
            if (row.toString().indexOf(text) !== -1)
                // append to array
                butTxArr = butTxArr.concat(row);
        })
    })
    // we're done!
    console.log(butTxArr)
});
$(文档).ready(函数(){
风险值数据=[
[“水果”、“荔枝魔法”、“黄昏”],
[“蔬菜”、“长豆”、“狂暴”],
[“水果”、“芒果香甜”、“黎明”]
];
$(“#intoArr”)。单击(函数(){
var butTxArr=[];
$('.mood')。每个(函数(){
//修剪按钮文本
var text=$(this.text().replace(/^\s*/g')。replace(/\s*$/g');
data.forEach(函数(行){
//查看该行是否包含文本
if(row.toString().indexOf(text)!=-1)
//附加到数组
butTxArr=butTxArr.concat(行);
})
})
//我们完了!
警报(butTxArr)
});
});

芒果
荔枝
显示类似这样的内容

$("#intoArr").click(function () {
    var butTxArr = [];
    $('.mood').each(function () {
        // trim button text
        var text = $(this).text().replace(/^\s*/g, '').replace(/\s*$/g, '');
        data.forEach(function (row) {
            // see if the row contains the text
            if (row.toString().indexOf(text) !== -1)
                // append to array
                butTxArr = butTxArr.concat(row);
        })
    })
    // we're done!
    console.log(butTxArr)
});
$(文档).ready(函数(){
风险值数据=[
[“水果”、“荔枝魔法”、“黄昏”],
[“蔬菜”、“长豆”、“狂暴”],
[“水果”、“芒果香甜”、“黎明”]
];
$(“#intoArr”)。单击(函数(){
var butTxArr=[];
$('.mood')。每个(函数(){
//修剪按钮文本
var text=$(this.text().replace(/^\s*/g')。replace(/\s*$/g');
data.forEach(函数(行){
//查看该行是否包含文本
if(row.toString().indexOf(text)!=-1)
//附加到数组
butTxArr=butTxArr.concat(行);
})
})
//我们完了!
警报(butTxArr)
});
});

芒果
荔枝

Show
我会这样做:

var butTxArr = [];

// create a temporary array
var temp = [];
$("#intoArr").click(function () {
    $('.mood').each(function () {

        // grab the text from the mood class
        var txt = $(this).text();

        // loop over the data array
        for (var i = 0, l = arr.length; i < l; i++) {

            // use `some` to check to see if the text appears
            // in any of the element, and if it does, add it
            // to the temporary array
            var found = arr[i].some(function (el) { return el.indexOf(txt) > -1; });
            if (found) temp.push(arr[i]);
        }
    });

    // flatten the temporary array
    butTxArr = [].concat.apply([], temp);
});
$("#intoArr").click(function(){     
    $('.mood').each(function(){
        for (var i=0;i<array.length;i++) {            
            if(array[i].toString().indexOf($(this).text()) > -1) {                
                butTxArr.push(array[i]);                   
            }
        }              
    })

    for (var a=0;a<butTxArr.length;a++) {
        alert(butTxArr[a]);
    }
});
var butTxArr=[];
//创建一个临时数组
var-temp=[];
$(“#intoArr”)。单击(函数(){
$('.mood')。每个(函数(){
//从mood类中抓取文本
var txt=$(this.text();
//在数据数组上循环
对于(变量i=0,l=arr.length;i-1;});
如果(发现)温度推送(arr[i]);
}
});
//展平临时阵列
butTxArr=[].concat.apply([],温度);
});

我会这样处理:

var butTxArr = [];

// create a temporary array
var temp = [];
$("#intoArr").click(function () {
    $('.mood').each(function () {

        // grab the text from the mood class
        var txt = $(this).text();

        // loop over the data array
        for (var i = 0, l = arr.length; i < l; i++) {

            // use `some` to check to see if the text appears
            // in any of the element, and if it does, add it
            // to the temporary array
            var found = arr[i].some(function (el) { return el.indexOf(txt) > -1; });
            if (found) temp.push(arr[i]);
        }
    });

    // flatten the temporary array
    butTxArr = [].concat.apply([], temp);
});
$("#intoArr").click(function(){     
    $('.mood').each(function(){
        for (var i=0;i<array.length;i++) {            
            if(array[i].toString().indexOf($(this).text()) > -1) {                
                butTxArr.push(array[i]);                   
            }
        }              
    })

    for (var a=0;a<butTxArr.length;a++) {
        alert(butTxArr[a]);
    }
});
var butTxArr=[];
//创建一个临时数组
var-temp=[];
$(“#intoArr”)。单击(函数(){
$('.mood')。每个(函数(){
//从mood类中抓取文本
var txt=$(this.text();
//在数据数组上循环
对于(变量i=0,l=arr.length;i-1;});
如果(发现)温度推送(arr[i]);
}
});
//展平临时阵列
butTxArr=[].concat.apply([],温度);
});

我会这样处理:

var butTxArr = [];

// create a temporary array
var temp = [];
$("#intoArr").click(function () {
    $('.mood').each(function () {

        // grab the text from the mood class
        var txt = $(this).text();

        // loop over the data array
        for (var i = 0, l = arr.length; i < l; i++) {

            // use `some` to check to see if the text appears
            // in any of the element, and if it does, add it
            // to the temporary array
            var found = arr[i].some(function (el) { return el.indexOf(txt) > -1; });
            if (found) temp.push(arr[i]);
        }
    });

    // flatten the temporary array
    butTxArr = [].concat.apply([], temp);
});
$("#intoArr").click(function(){     
    $('.mood').each(function(){
        for (var i=0;i<array.length;i++) {            
            if(array[i].toString().indexOf($(this).text()) > -1) {                
                butTxArr.push(array[i]);                   
            }
        }              
    })

    for (var a=0;a<butTxArr.length;a++) {
        alert(butTxArr[a]);
    }
});
var butTxArr=[];
//创建一个临时数组
var-temp=[];
$(“#intoArr”)。单击(函数(){
$('.mood')。每个(函数(){
//从mood类中抓取文本
var txt=$(this.text();
//在数据数组上循环
对于(变量i=0,l=arr.length;i-1;});
如果(发现)温度推送(arr[i]);
}
});
//展平临时阵列
butTxArr=[].concat.apply([],温度);
});

我会这样处理:

var butTxArr = [];

// create a temporary array
var temp = [];
$("#intoArr").click(function () {
    $('.mood').each(function () {

        // grab the text from the mood class
        var txt = $(this).text();

        // loop over the data array
        for (var i = 0, l = arr.length; i < l; i++) {

            // use `some` to check to see if the text appears
            // in any of the element, and if it does, add it
            // to the temporary array
            var found = arr[i].some(function (el) { return el.indexOf(txt) > -1; });
            if (found) temp.push(arr[i]);
        }
    });

    // flatten the temporary array
    butTxArr = [].concat.apply([], temp);
});
$("#intoArr").click(function(){     
    $('.mood').each(function(){
        for (var i=0;i<array.length;i++) {            
            if(array[i].toString().indexOf($(this).text()) > -1) {                
                butTxArr.push(array[i]);                   
            }
        }              
    })

    for (var a=0;a<butTxArr.length;a++) {
        alert(butTxArr[a]);
    }
});
var butTxArr=[];
//创建一个临时数组
var-temp=[];
$(“#intoArr”)。单击(函数(){
$('.mood')。每个(函数(){
//从mood类中抓取文本
var txt=$(this.text();
//在数据数组上循环
对于(变量i=0,l=arr.length;i-1;});
如果(发现)温度推送(arr[i]);