Live is hard when you are alone ... but in the end its easier.
here is my working code now.
may be there is somebody here in this group who need it or wants to
make suggestions for improvements
window.addEvent('domready', function()
{
function muller(item)
{
//item
var archiveHTML="<h3>Archive text von joe</h3>";
archiveHTML+="<div class=\"single\" id=\""+item.id+"\">";
archiveHTML+="<div class=\"post\"><div class=\"day
\">"+item.loan.name+" / "+item.id+"</div>";
archiveHTML+="<div class=\"month\">"+item.loan.activity+ " / "
+item.loan.use+ " / " +item.loan.loan_amount+" /
"+item.loan.funded_amount+"</div>";
archiveHTML+="</div><h4>"+item.loan.image.id+" <span class=
\"author\"> ImageID und zufallsnummer "+currentIndex+"</span></h4>";
archiveHTML+="</div><img src=\"
http://www.kiva.org/img/w200h200/"+item.loan.image.id+".jpg\">";
archiveHTML+="<p>"+item.loan.location.country+ " / "
+item.loan.location.town+ "</p></div>";
writehere.set('html', archiveHTML); //löscht vorhandenes und
trägt neues ein.
};
function nextItem()
{
currentIndex++;
if(currentIndex > arrayLaenge){currentIndex = 0;}
muller(JSONResponse.lending_actions[currentIndex]);
};
function prevItem()
{
currentIndex--;
if(currentIndex < 0){currentIndex = arrayLaenge;}
muller(JSONResponse.lending_actions[currentIndex]);
};
var path = '
http://api.kivaws.org/v1/';var writehere = $('writehere');
var arrayLaenge = 0;
var JSONResponse = {};
var currentIndex = 0;
var request = new Request.JSON(
{
url: path + 'lending_actions/recent.json',
onComplete: function(jsonObj) {
currentIndex = $random(0, jsonObj.lending_actions.length-1);
arrayLaenge = jsonObj.lending_actions.length-1;
muller(jsonObj.lending_actions[currentIndex]);
//we assign JSONResponse to the response of the request
JSONResponse = jsonObj;
}
}).send();
$('more_changer').addEvent('click', function() {nextItem();});
$('prev_changer').addEvent('click', function() {prevItem();});
//console.log(JSONResponse);
});
On 31 Okt., 11:50, hamburger <
[hidden email]> wrote:
> Thx CroNiX for your answer.
> arrayLaenge and rand is defined. (as you see in my second post)
> The test alert(rand) shows OK.
> But Indeed the problem is how to give the new array[index] to addText
> = function muller(item).
> Thats what I dont know how.
> Normally I do that like his: states.blah[index].date
> I dont get to do it with this json stuff. (here I dont understand the
> "item" either)
> any further help?
>
> On 30 Okt., 22:35, CroNiX <
[hidden email]> wrote:
>
>
>
> > function setStateForItem(item)
> > {
> > new_item = rand +1;
> > if(new_item >(arrayLaenge)){new_item=0;};
> > muller(new_item);
>
> > };
>
> > This function does not know what 'arrayLaenge' is because its not
> > defined within or passed to the function. You also never use 'item'
> > in the function. 'rand' is not defined either. If those are defined
> > elsewhere you need to pass them to the function as well. Basically,
> > you have a scope problem.
>
> > On Oct 30, 1:30 pm, hamburger <
[hidden email]> wrote:
>
> > > hello,
> > > everything with jason works fine now.
> > > only the function setStateForItem(item) to scroll to next gives the
> > > error:undefined.
> > > can somebody have a quick look?
> > > thx
>
> > > On 30 Okt., 20:45, hamburger <
[hidden email]> wrote:
>
> > > > Hello, I think i do not have a jason problem.
> > > > I'am would like to read the hole file witch is provided by kiva.org
> > > > this part works!
> > > > I'am a newbe and have problems with the syntax and sometimes with the
> > > > object-oriented-stuff.
>
> > > > do i find the Mooshell's built-in 'JSON echo' here:
http://mooshell.net/json/> > > > ???
> > > > I have the same error here.
> > > > thx for your fast answer
>
> > > > On 30 Okt., 20:27, Sanford Whiteman <
[hidden email]>
> > > > wrote:
>
> > > > > > but i get an access error i dont have it with my browser
>
> > > > > B/c of the same-origin security policy.
>
> > > > > Use Mooshell's built-in 'JSON echo' feature to simulate XHR response.
> > > > > There is a demo on the site.
>
> > > > > -- Sandy- Zitierten Text ausblenden -
>
> > > > - Zitierten Text anzeigen -- Zitierten Text ausblenden -
>
> > - Zitierten Text anzeigen -- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -