[英]$.parseJSON(…).each is not a function
在一個js文件中,我有下面的代碼。
有了這個語法就可以了
$(jQuery.parseJSON(category)).each(function() {
$(selector).append($('<option>').text(this.name).attr('value', this.contactCategoryId));
});
有了這個失敗
$.parseJSON(category).each(function () {
$(selector).append($('<option>').text(this.name).attr('value', this.contactCategoryId));
});
$ .parseJSON(...)。每個不是函數
編輯
工作正常
$.each(jQuery.parseJSON(category), function () {
...
});
也許有更好的解決方案。
jQuery.parseJSON(json)
接受格式正確的JSON字符串並返回結果JavaScript值 。
所以
$.parseJSON(category)
返回一個javascript值。
在哪里
$($.parseJSON(category))
返回jQuery對象
作為jquery,每個只能與jQuery對象一起使用。 您收到錯誤$ .parseJSON(...)。每個不是函數
就您而言 ,這是使用jQuery each
的正確方法。
$(jQuery.parseJSON(category)).each(function() {
$(selector).append($('<option>').text(this.name).attr('value', this.contactCategoryId));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.