在任何人爆炸之前,我是新编码的人。我尝试了几件事似乎什么都没有用,而且我害怕我已经解决了。
问题。
// Each of these sample items should have a reference to a particular
// group.
var sampleItems = [
{ group: sampleGroups[0], title: "Ticker 1", subtitle: "2278.59" , txt1: "+ 11.52", txt2: "+ 0.59%", description: itemDescription, content: itemContent, backgroundImage: "../../images/Assets/itemUpArrow.png" },
我制作了一个api自动收报机,我通常使用
<div id="ticker"</div>
我怎么不能用它来代替“2278.59:副标题。 有什么方法可以解决这个问题而不必失去理智吗? 我只想要外部的api数据在那个位置。
更新:这就是我想要做的事情:
{ group: sampleGroups[0], title: "Lorem Ipsusssm", subtitle: "<div id="ticker"> </div>", txt1: "+ 11.52", txt2: "+ 0.59%", description: itemDescription, content: itemContent, backgroundImage: "../../images/Assets/itemUpArrow.png" },
我怎么得到Javascript运行时错误:syntaxerror。
也是这个
Warning 4 Validation (HTML5): Element 'div' cannot be nested within element 'h4'. C:\Users\Noah\Desktop\Development\ah\pages\groupedItems\groupedItems.html 82 55
答案 0 :(得分:0)
不确定您的问题是什么,但问题可能是您没有关闭div标签。
<div id="ticker"> </div>
应该修复它,但也在div中添加[space],因此它不被视为空值
答案 1 :(得分:0)
如果无法提供帮助,请忽略以下内容,但请点击上面的更新:
subtitle: "<div id="ticker"> </div>"
这会导致语法错误。替换为:
subtitle: "<div id='ticker'> </div>"
你忘记了你的数组上的结束]
(虽然因为只有一个对象你可能只是把它作为没有括号的直接对象)。
从以下两个选项中选择:
var sampleItems = [{
group: sampleGroups[0],
title: "Ticker 1",
subtitle: "2278.59",
txt1: "+ 11.52",
txt2: "+ 0.59%",
description: itemDescription,
content: itemContent,
backgroundImage: "../../images/Assets/itemUpArrow.png"
}]
或我的建议(假设此数组中没有其他对象):
var sampleItems = {
group: sampleGroups[0],
title: "Ticker 1",
subtitle: "2278.59",
txt1: "+ 11.52",
txt2: "+ 0.59%",
description: itemDescription,
content: itemContent,
backgroundImage: "../../images/Assets/itemUpArrow.png"
}
答案 2 :(得分:0)
如果你想迭代数组对象的属性并希望改变它的值,那么它对你有用
<!DOCTYPE html>
<html>
<head>
<script>
// group.
//please remove sampleGroups, itemDescription, itemContent when you use this code
var sampleGroups = ['f', 'g'];
var itemDescription= "ss";
var itemContent= "aa";
var sampleItems = [
{ group: sampleGroups[0], title: "Ticker 1", subtitle: "2278.59" , txt1: "+ 11.52", txt2: "+ 0.59%", description: itemDescription, content: itemContent, backgroundImage: "../../images/Assets/itemUpArrow.png" },
{ group: sampleGroups[0], title: "Ticker 2", subtitle: "3333", txt1: "+ 11.52", txt2: "+ 0.59%", description: itemDescription, content: itemContent, backgroundImage: "../../images/Assets/itemUpArrow.png" }
];
//put the value into relaceVal in order which you
//want to replace with elements of sampleItems
var replaceVal = [230, 582];
for(var i=0; i<sampleItems.length; i++){
for(key in sampleItems[i]){
if(key == 'subtitle'){
sampleItems[i].subtitle = replaceVal[i];
}
}
}
//alert new value 230, 582 respectively
alert(sampleItems[0].subtitle);
alert(sampleItems[1].subtitle);
</script>
</body>
</html>