locked
Error when trying to search Unable to get property 'indexOf' of undefined or null reference

    Question

  • Dear Friends: I'm working in a very simple split app, that gets its data from a JSON text file. It worked fine until I tried to add search.

    I follwed the tutorial very carefully, but every time I try to search I get this error

    0x800a138f - JavaScript runtime error: Unable to get property 'indexOf' of undefined or null reference

    The error occurs in the function searchData, specifically in the line in red

    _searchData: function (queryText) {
    var originalResults;
    if (window.Data) {
    originalResults = Data.items.createFiltered(function (item) {
    return (item.title.indexOf(queryText) >= 0 || item.description.indexOf(queryText) >= 0);
    });
    } else {
    originalResults = new WinJS.Binding.List();
    }
    return originalResults;
    }

    At first I thought the message was pretty obvious, but when I put some watches, I saw that both itlem.title and item.description had the content they were supposed to have. Also, th app has no problems displaying the info from these fields. If I delete the item.description filed, I don;t get any errors, but my searches return blank. I'm guessing that the fact that description contains HTML code maught have something to do with this, but I don't know aht I could do about this.

    My data looks like this

    {
    "group": {"key": "A", "title": "A", "subtitle": "", "backgroundImage": "images/a.png", "description": ""},
    "title": "Accompaniment",
    "description":"<p>The physical presence of civilians, sometimes foreign volunteers, with the aim of protecting activists from violent attacks or intimidation and encouraging their continued activities. The use of accompaniment, a method of non-violent struggle, carries with it the possibility that politically motivated violence perpetrated against activists will result in undesirable consequences, usually in the form of international sanctions, against the sponsors of such violence. This act of ‘witness’, as it is sometimes termed, is highly contextualised given that the parties and circumstances are different in every case. Accompaniment ultimately aims not only to protect, but also to create space and opportunities for activists to continue diverse political and social work, such as voter registration and voting, demonstrations and vigils, or news reporting and documentation. As persons willing to endanger their own lives for the protection of others, accompaniment volunteers are often viewed as occupying a relatively moral high ground.</p><p>The concept of accompaniment has a long and varied history although valid examples are not framed as such. Historical incidents can be traced back to the Roman Empire, but the more modern notion of international, non-governmental protective presence dates to the formation of the International Committee of the Red Cross (ICRC) in 1863. Accompaniment has since been utilised in various movements, from the anti-colonial and independence drives in India to the civil rights movement in the United States, and is the primary impetus behind organisations such as Amnesty International and a host of other human rights–monitoring groups.</p><p>As an act conducted in the hope of stopping an anticipated act of aggression, accompaniment represents a form of deterrence. Its effectiveness, however, is difficult to discern. How does one measure the value of a threatening, intimidating, or violent act that does not occur? In addition, the circumstances in which volunteers conduct accompaniment are not always straightforward, and the perpetrators of political violence and intimidation may elude easy identification, which may result in false accusations or a tendency to scapegoat.</p><p>Nonetheless, the act of accompaniment remains highly commendable in situations that allow individuals essentially to act as unarmed bodyguards, often spending extended, continuous periods alongside activists under harsh political and often lifethreatening conditions. Some of the broadly defined motivations for accompaniment include a general humanitarian concern, a personal connection with the activists who are in need of protection or assistance, some form of shared perspective with such activists, and a desire to offer professional services. Not bound by national or international mandates, borders, or processes, accompaniment adds a complex dimension to the global struggle for justice and human rights.</p><p>For further reading, see Liam Mahony and Luis Enrique Eguren, <em>Unarmed Bodyguards: International Accompaniment for the Protection of Human Rights</em> (Hartford, Kumarian Press, 1997).</p>"
    }

    I know I must be doing something dumb, but I haven't been able to figure out what

    Any help will be greatly appreciated


    Wednesday, November 21, 2012 5:16 PM

Answers