在下面的代码中,我将item复制到dummyItem然后更改了dummyItem的description属性,那么为什么Item的description属性也会被更改。 customFilter函数被一个接一个地调用no。
Item structure
item = {brand: "test_brand", categorygroup: "Food & Drink", categoryid: 131, categorytext: "Breweries", description:"<b><i>the new description</i><b>", listprice: 123, noofrewards: 14, supplieditems: 1, title: "test_dev"}
customFilter : function(item, args) {
if (args.searchString != "" && item.productid.toFixed(2).indexOf(args.searchString.toLowerCase()) == -1
&& item.shortid.toLowerCase().indexOf(args.searchString.toLowerCase()) == -1
&& item.title.toLowerCase().indexOf(args.searchString.toLowerCase()) == -1
&& item.brand.toLowerCase().indexOf(args.searchString.toLowerCase()) == -1
&& item.description.toLowerCase().indexOf(args.searchString.toLowerCase()) == -1
&& item.categorytext.toLowerCase(2).indexOf(args.searchString) == -1
&& item.companyid.toFixed(2).indexOf(args.searchString) == -1
&& item.listprice.toFixed(2).indexOf(args.searchString) == -1
&& item.currency.toLowerCase().indexOf(args.searchString.toLowerCase()) == -1) {
return false;
}
var dummyItem = item;
dummyItem.description = $('<div></div>').html(item.description).text();
$self.filteredData.push(dummyItem);
return true;
},
答案 0 :(得分:0)
您指的是同一个对象:
var dummyItem = item;
var src = {
'a': 45
};
console.log('src, ', src);
var trg = src; // trg is pointing to src
console.log('trg, ', trg);
var cpy = {
'a': 45
};
console.log('cpy, ', cpy);
console.log('src === trg, ', src === trg); //true
console.log('src === cpy, ', src === cpy); //false
Open console ...