按钮点击时在JSON中存储值 [英] store value in JSON on button click
本文介绍了按钮点击时在JSON中存储值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Demo Here
解决方案
可以简单地使用作为
循环来检查具有该标题的元素是否已经存在:
function alreadyAdded(itemTitle){
for(var i = 0; i< objArray.length; i ++){
if(objArray [i] .title === itemTitle){
返回true;
}
}
返回false;
};
另外,您并未使用json对象,只是一个JavaScript数组。
I am new in JSON, i am trying to save data using JSON. I have a list of element with some button when we click the button i want the corresponding value of button are save in JSON. I am also want to compare the title with already exists in JSON.
Demo Here
解决方案
You can simply use a for
loop to check if the element with that title is already there:
function alreadyAdded(itemTitle) {
for (var i = 0; i < objArray.length; i++) {
if (objArray[i].title === itemTitle) {
return true;
}
}
return false;
};
Also, you are not using a json object, just a JavaScript array.
这篇关于按钮点击时在JSON中存储值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文