我有以下代码块实例化typeahead
$("#searchbox").typeahead({
minLength: 3,
}, {
name: "Type0",
displayKey: "name",
source: bloodHound[0].ttAdapter(),
templates: {
header: "<h4 class='typeahead-header'><img src='Type0.png'>Type0</h4>",
suggestion: Handlebars.compile(["{{name}}<br><small>{{address}} </small>"].join(""))
}
}, {
name: "Type1",
displayKey: "name",
source: bloodHound[1].ttAdapter(),
templates: {
header: "<h4 class='typeahead-header'><img src='Type1.png'>Type1</h4>",
suggestion: Handlebars.compile(["{{name}}<br><small>{{address}}</small>"].join(""))
}
}
)
如果我想添加其他类型,例如Type2我必须复制并粘贴块,因此效率不高。我有一个名为types的数组中可用的类型。
如何使用一个循环数组的代码块并创建与上面相同的结果。所有建议都赞赏。
答案 0 :(得分:0)
我不知道你的char sentence[100] = "";
cin.getline(sentence, 100);
char letters[100] = "";
int counter = 0;
for (int i = 0; i < strlen(sentence); i++) {
cout << sentence[i] << endl;
letters[i] = sentence[i];
}
for (int i = 0; i < strlen(sentence); i++) {
for (int j = 0; j < strlen(sentence); j++) {
if (letters[j]==sentence[i]) {
counter++;
cout << letters[j] << " occurs " << counter << " in the sentence" << endl;
}
}
}
数组应该是什么样的,但这是我如何设置的:
types