jQuery Mobile getJSON get data with var
jQuery Mobile getJSON get data with var
例如,我有一个 json 文件,其中包含福特和大众汽车的汽车。现在我有一个存储"福特"或"大众"的变量。如何将此变量与数据选择结合使用。
$.getJSON('file.json', function(data) {
$.each(data.ford, function(i, item) {
//do something
});
});
$.getJSON('file.json', function(data) {
$.each(data.volkswagen, function(i, item) {
//do something
});
});
我的意思是像
var brand = 'ford';
data.+brand
你可以这样做:
var brand = 'ford';
$.each(data[brand], function(i, item) {....
您可以使用以下内容访问对象中的该项:
var brand = 'ford';
data[brand];
您可以在此处阅读有关点和方括号表示法的更多信息。
试试这个,
var brand = 'ford';
$.getJSON('file.json', function(data) {
$.each(data[brand], function(i, item) {
//do something
});
});
相关文章:
- Fighting with FRP
- 控制台返回var不是't定义,但它是
- issue with FB.Event.subscribe
- 从var向代码隐藏函数传递值
- 如何通过引用var Using DataTables来进行分页或排序
- jQuery语法添加了var
- 如何将具有文本类型值的var放入jQuery函数中
- JS:检查URL中的参数,然后迭代一个参数为var的函数
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- Understanding Javascript scope with "var that = this&qu
- Joomla javascript var with HTML code
- jQuery Mobile getJSON get data with var
- Javascript - querySelectorAll with a var
- Javascript with Selenium WebDriver: "Can't find var
- if($(var).css('display') == "block") with
- Trouble with Javascript VAR
- JavaScript: Declaring VAR with 'or' statement