I want to create a for loop that will generate a new element for sampleItems
based on a fixed number set in a for loop.
var list = new WinJS.Binding.List();
var groupedItems = list.createGrouped(
function groupKeySelector(item) { return item.group.key; },
function groupDataSelector(item) { return item.group; }
);
generateSampleData().forEach(function (item) {
list.push(item);
});
function generateSampleData() {
var sampleGroups = [
{ key: "group1", title: "Event1", backgroundImage: "/images/event1.jpg"}
];
var sampleItems = [
{ group: sampleGroups[0], title: "Item Title: 1", content: "http://192.168.201.41/Stream" + [i] + ".mp4", backgroundImage: "/images/image1.jpg" }
];
return sampleItems;
}
I tried to place a for loop within sampleItems
but i'm not allowed place the loop there.
I want to create a for loop that will generate a new element for sampleItems
based on a fixed number set in a for loop.
var list = new WinJS.Binding.List();
var groupedItems = list.createGrouped(
function groupKeySelector(item) { return item.group.key; },
function groupDataSelector(item) { return item.group; }
);
generateSampleData().forEach(function (item) {
list.push(item);
});
function generateSampleData() {
var sampleGroups = [
{ key: "group1", title: "Event1", backgroundImage: "/images/event1.jpg"}
];
var sampleItems = [
{ group: sampleGroups[0], title: "Item Title: 1", content: "http://192.168.201.41/Stream" + [i] + ".mp4", backgroundImage: "/images/image1.jpg" }
];
return sampleItems;
}
I tried to place a for loop within sampleItems
but i'm not allowed place the loop there.
-
what is
[i]
in the hash ofsampleItems
? Is it value that you assume you will have in for loop? :P – RAJ Commented Jul 21, 2014 at 11:15 -
It would be useful if you provided the code for
for
loop you have tried to put intosampleItems
. – Andrey Shchekin Commented Jul 21, 2014 at 11:16 -
i
will be a value! I just want a basic for loopvar streams = 7 for(i=0; i<streams; i++)
– KathyS Commented Jul 21, 2014 at 11:18 - Have a look stackoverflow./questions/24863630/… – RAJ Commented Jul 21, 2014 at 11:29
- @KathyS As a good learner and contributor, if you found any answer useful, you should upvote for that – RAJ Commented Aug 4, 2014 at 17:05
2 Answers
Reset to default 4As per conversation in question ments, here is the basic array population code for js:
var streams = 7;
var sampleItems = [];
for(i = 0; i < streams; i++) {
sampleItems.push({'a': 'b', 'c': 'd'})
}
Replace {'a': 'b', 'c': 'd'}
with desired key-value pairs
Well you are looping over an array containing one object as entry. what you probably want to do is to discard you object structure pletely and just use an simple array like:
var sampleItems = [ sampleGroups[0], "Item Title: 1", ..... ];
you could also make it a an actual object without using arrays but it seems to me that you want to use the List
. If no List
ist necessary just put the whole object genereated by
generateSampleData
into you object or append it to an existing object.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744218443a4563664.html
评论列表(0条)