2012-05-13 66 views
1

我想加载一个JSON存储与我从搜索服务器(Solr)检索的数据。 在Firebug中,我可以看到响应(Solr返回数据),但无法使商店加载传入数据。JSONP Extjs4问题

请注意,我在本地工作(solr的地址:localhost:8080/blah/blah和我的应用程序的地址:localhost:8500/blah/blah)。

我的店铺代码:

Ext.define('Ledger.store.Searchstore', { 
    extend: 'Ext.data.Store', 

    requires: ['Ledger.model.Searchmodel'], 

    model: 'Ledger.model.Searchmodel', 

    fields: [ 
     {name:'id', mapping:'id'}, 
     {name: 'model', mapping: 'title'}, 
     {name: 'firstname', mapping: 'firstname'}, 
     {name: 'lastname', mapping: 'lastname'}, 
     {name: 'title', mapping: 'title'}, 
     {name: 'biog', mapping: 'biog'} 
     ], 

    autoLoad: true, 

    proxy: { 
     type:'jsonp', 
     url: 'http://127.0.0.1:8080/solr/select/?q=*:*&fq=model:book&wt=json', 
     //noCache: false, 
     //actionMethods:{create: "POST", read: "POST", update: "POST", destroy: "POST"}, 
     //callbackKey: 'myCallback', 
     reader:{ 
      type: 'json', 
      root: 'response.docs' 
     } 
    } 

}); 

我的模型代码:

Ext.define('Ledger.model.Searchmodel',{ 
    extend:'Ext.data.Model', 

    fields:[ 
     {name:'id', mapping:'id'}, 
     {name: 'model', mapping: 'title'}, 
     {name: 'firstname', mapping: 'firstname'}, 
     {name: 'lastname', mapping: 'lastname'}, 
     {name: 'title', mapping: 'title'}, 
     {name: 'biog', mapping: 'biog'} 
    ] 

}); 

从搜索服务器传入的JSON(它是有效的):

{ 
    "responseHeader":{ 
    "status":0, 
    "QTime":1, 
    "params":{ 
     "indent":"on", 
     "q":"*:*", 
     "wt":"json", 
     "fq":"model:book"}}, 
    "response":{"numFound":8,"start":0,"docs":[ 
     { 
     "id":"1", 
     "last_modified":"2012-05-12 15:33:07.0", 
     "model":"book", 
     "title":"The Art of Fielding: A Novel", 
     "fake_id":"b_1", 
     "biog":"At Westish College, a small school on the shore of Lake Michigan, baseball star Henry Skrimshander seems destined for big league stardom. But when a routine throw goes disastrously off course, the fates of five people are upended.\nHenry's fight against self-doubt threatens to ruin his future. College president Guert Affenlight, a longtime bachelor, has fallen unexpectedly and helplessly in love. Owen Dunne, Henry's gay roommate and teammate, becomes caught up in a dangerous affair. Mike Schwartz, the Harpooners' team captain and Henry's best friend, realizes he has guided Henry's career at the expense of his own. And Pella Affenlight, Guert's daughter, returns to Westish after escaping an ill-fated marriage, determined to start a new life.\nAs the season counts down to its climactic final game, these five are forced to confront their deepest hopes, anxieties, and secrets. In the process they forge new bonds, and help one another find their true paths. Written with boundless intelligence and filled with the tenderness of youth, The Art of Fielding is an expansive, warmhearted novel about ambition and its limits, about family and friendship and love, and about commitment--to oneself and to others.\t\t\t\t\t"}, 
     { 
     "id":"2", 
     "last_modified":"2012-05-12 15:33:55.0", 
     "model":"book", 
     "title":"The Tiger's Wife", 
     "fake_id":"b_2", 
     "biog":"Starred Review. The sometimes crushing power of myth, story, and memory is explored in the brilliant debut of Obreht, the youngest of the New Yorker's 20-under-40. Natalia Stefanovi, a doctor living (and, in between suspensions, practicing) in an unnamed country that's a ringer for Obreht's native Croatia, crosses the border in search of answers about the death of her beloved grandfather, who raised her on tales from the village he grew up in, and where, following German bombardment in 1941, a tiger escaped from the zoo in a nearby city and befriended a mysterious deaf-mute woman. The evolving story of the tiger's wife, as the deaf-mute becomes known, forms one of three strands that sustain the novel, the other two being Natalia's efforts to care for orphans and a wayward family who, to lift a curse, are searching for the bones of a long-dead relative; and several of her grandfather's stories about Gavran Gailé, the deathless man, whose appearances coincide with catastrophe and who may hold the key to all the stories that ensnare Natalia. Obreht is an expert at depicting history through aftermath, people through the love they inspire, and place through the stories that endure; the reflected world she creates is both immediately recognizable and a legend in its own right. Obreht is talented far beyond her years, and her unsentimental faith in language, dream, and memory is a pleasure."}, 
     { 
     "id":"3", 
     "last_modified":"2012-05-12 15:34:00.0", 
     "model":"book", 
     "title":"State of Wonder", 
     "fake_id":"b_3", 
     "biog":"In State of Wonder, pharmaceutical researcher Dr. Marina Singh sets off into the Amazon jungle to find the remains and effects of a colleague who recently died under somewhat mysterious circumstances. But first she must locate Dr. Anneck Swenson, a renowned gynecologist who has spent years looking at the reproductive habits of a local tribe where women can conceive well into their middle ages and beyond. Eccentric and notoriously tough, Swenson is paid to find the key to this longstanding childbearing ability by the same company for which Dr. Singh works. Yet that isn’t their only connection: both have an overlapping professional past that Dr. Singh has long tried to forget. In finding her former mentor, Dr. Singh must face her own disappointments and regrets, along with the jungle’s unforgiving humidity and insects, making State of Wonder a multi-layered atmospheric novel that is hard to put down. Indeed, Patchett solidifies her well-deserved place as one of today’s master storytellers. Emotional, vivid, and a work of literature that will surely resonate with readers in the weeks and months to come, State of Wonder truly is a thing of beauty and mystery, much like the Amazon jungle itself."}, 
     { 
     "id":"4", 
     "last_modified":"2012-05-12 15:34:05.0", 
     "model":"book", 
     "title":"The Marriage Plot", 
     "fake_id":"b_4", 
     "biog":"A stunning novel—erudite, compassionate and penetrating in its analysis of love relationships. Eugenides focuses primarily on three characters, who all graduate from Brown in 1982. One of the pieces of this triangle is Madeleine Hanna, who finds herself somewhat embarrassed to have emerged from a “normal” household in New Jersey (though we later find out the normality of her upbringing is only relative). She becomes enamored with Leonard, a brilliant but moody student, in their Semiotics course, one of the texts being, ironically, Roland Barthes’ A Lover’s Discourse, which Madeleine finds disturbingly problematic in helping her figure out her own love relationship. We discover that Leonard had been diagnosed with bipolar disorder during his first year at Brown, and his struggle with mood swings throughout the novel is both titanic and tender. The third major player is Mitchell, a Religious Studies major who is also attracted to Madeleine but whose reticence she finds both disturbing and incomprehensible. On graduation day, Leonard has a breakdown and is hospitalized in a mental-health ward, and Madeleine shows her commitment by skipping the festivities and seeking him out. After graduation, Leonard and Madeleine live together when Leonard gets an internship at a biology lab on Cape Cod, and the spring after graduation they marry, when Leonard is able to get his mood swings under temporary control. Meanwhile Mitchell, who takes his major seriously, travels to India seeking a path—and briefly finds one when he volunteers to work with the dying in Calcutta. But Mitchell’s road to self-discovery eventually returns him to the States—and opens another opportunity for love that complicates Madeleine’s life. "}, 
     { 
     "id":"5", 
     "last_modified":"2012-05-12 15:34:07.0", 
     "model":"book", 
     "title":"Steve Jobs", 
     "fake_id":"b_5", 
     "biog":"Based on more than forty interviews with Jobs conducted over two years—as well as interviews with more than a hundred family members, friends, adversaries, competitors, and colleagues—Walter Isaacson has written a riveting story of the roller-coaster life and searingly intense personality of a creative entrepreneur whose passion for perfection and ferocious drive revolutionized six industries: personal computers, animated movies, music, phones, tablet computing, and digital publishing.\r\nAt a time when America is seeking ways to sustain its innovative edge, and when societies around the world are trying to build digital-age economies, Jobs stands as the ultimate icon of inventiveness and applied imagination. He knew that the best way to create value in the twenty-first century was to connect creativity with technology. He built a company where leaps of the imagination were combined with remarkable feats of engineering.\nAlthough Jobs cooperated with this book, he asked for no control over what was written nor even the right to read it before it was published. He put nothing off-limits. He encouraged the people he knew to speak honestly. And Jobs speaks candidly, sometimes brutally so, about the people he worked with and competed against. His friends, foes, and colleagues provide an unvarnished view of the passions, perfectionism, obsessions, artistry, devilry, and compulsion for control that shaped his approach to business and the innovative products that resulted.\nDriven by demons, Jobs could drive those around him to fury and despair. But his personality and products were interrelated, just as Apple’s hardware and software tended to be, as if part of an integrated system. His tale is instructive and cautionary, filled with lessons about innovation, character, leadership, and values."}, 
     { 
     "id":"6", 
     "last_modified":"2012-05-12 15:34:10.0", 
     "model":"book", 
     "title":"The Mill River Recluse", 
     "fake_id":"b_6", 
     "biog":"Having been loaned a Kindle from a friend, I immediately went in search of books that were inexpensive. I stumbled on The Mill River Recluse and the reviews were what made me really want to read this book. Having never written a review before, when I completed this book I felt I HAD to write a review. I was so wonderfully surprised to the depth of characters, storylines and twists and turns along the way. I stayed up all night just to finish it!! I found myself chuckling at times and caught myself off guard with tears rolling down my face. You became part of Mill River and its community almost from the first page. I really didn't want the story to end.\nIf you have only one chance to read a good Kindle book - this is by far the one! I enjoyed it so much, that when I someday purchase my own Kindle, I will be adding (and most likely reading) this book again....one I DEFINATELY want to add to a 'forever' collection!"}, 
     { 
     "id":"7", 
     "last_modified":"2012-05-12 15:34:13.0", 
     "model":"book", 
     "title":"Chasing Amanda", 
     "fake_id":"b_7", 
     "biog":"In \"Chasing Amanda\" Melissa Foster guides us in helping Molly; wife, mother to a teenage son, search for a missing girl. The young girl has disappeared from their quiet, rural community; a place where things like this simply don't happen. For Molly, it's deja vu. Several years earlier, while living in Philadelphia, she witnessed a similar event. She did nothing at that time, and has been tormented by her inaction ever since.\nMolly's special gift, or curse, is her clairvoyance. She can sometimes 'see' things that others cannot. In Philadelphia, she failed the little girl, whose body was found shortly after. Now, she promised herself that she would not make that mistake again. Molly persists, using her clairvoyance and sheer stubbornness in an effort to find the child. In doing so, Molly exposes her town's shameful secrets, presenting a conclusion to this story, that I never saw coming!\nMelissa Foster's skill with her characters, drew me into the story immediately. The suspense that followed made this book a definite page-turner!"}, 
     { 
     "id":"13", 
     "last_modified":"2012-05-12 16:08:48.0", 
     "model":"book", 
     "title":"Kodokan Judo", 
     "fake_id":"b_13", 
     "biog":"Judo, or the Way of Gentleness, an ideal form of physical exercise and a reliable system, of self-defense, was specially created from traditional Japanese martial arts. This book by the creator of Kodokan judo is uniquely comprehensive and the most authoritative guide to this martial art ever published.\r\nOver a hundred years ago Jigoro Kano mastered swordsmanship and hand-to-hand combat. Failing to discover any underlying principle, he set about designing a new martial art to reflect the concept of maximum efficiency in the use of physical and mental energy. Today, the concepts and techniques of judo taught at the Kodokan are the ones originally devised by their creator and collected together in this book. Covering everything from the fundamental techniques to prearranged formal exercises for both men and women, the book offers detailed explanations of how techniques are combined in two types of practice: randori (free practice) and kata (the practice of forms). In addition to a discussion of traditional methods of resuscitation, the book concludes with a useful appendix of information on the founder and the Kodokan International Judo Center, and a glossary of judo terminology. Fully illustrated throughout, Kodokan Judo will help students and instructors everywhere to discover the principles, techniques, and spirit of this popular martial art."}] 
    }} 

某处我有一个按钮到“console.log”商店,但是当我打电话时(注意我已经在商店定义中将autoload属性设置为true),它是空的。当我通过AJAX代理加载上述JSON(将服务器的响应复制到JSON文件中)时,存储会加载数据。

什么问题?

回答

1

试试这几件事。

第一个将代理设置为模型不存入。我有很长一段时间同样的问题。然后尝试重新加载你的应用程序。

第二次设置root“docs”直接。

第三组一个Ledger.store.Searchstore.load();

最后我使用代理像这样的,我留给我的PHP文件如何读取远程文件:

proxy: { 
type: 'ajax', 
api: { 
    read: 'scripts/receive.php', 
    create: 'scripts/create.php?action=create', 
    update: 'scripts/create.php?action=update', 
    destroy:'scripts/destroy.php?action=destroy' 
}, 
+0

我用你的方法一致。但我正在尝试加入混音“jsonp”。无论如何,我会尝试几个小时,如果我没有成功,我会去服务器端。 谢谢 – anarchos78