سؤال

كيف يمكنني البحث في قاعدة البيانات للحصول على سجل محدد؟لقد حاولت البحث () و FindBy ()، ولكن كلاهما العودة -1. giveacodicetagpre.

لدي مربع تحرير وسرد مع قائمة العملاء.ما أريده هو أن أكون قادرا على تعيين قيمة افتراضية على هذا التحرير والسرد.لدي إعداد القيمة بشكل صحيح باستخدام SetValue ويمكنني حتى تعيين قيمة العرض باستخدام SetrawValue، لكنني لا أستطيع الاستعلام عن DataStore بناء على العميل والحصول على اسم الشركة لاستخدامها في SetrawValue.

هل هذا معنى؟

إليك رمز DataStore استجابة للأسئلة أدناه (آسف لن يسمح لي لصقها هناك) giveacodicetagpre.

هل كانت مفيدة؟

المحلول

There are several problems with your configuration. First of all the id-property of the read should be the idProperty-property. The the id-property of the store should be the storeId-property (id is deprecated). And then your variable is called frmClientStore while you're referencing clientStore in your code (might be a typo).

var frmClientStore = new Ext.data.Store({
    storeId: 'frmClientStore',
    proxy: new Ext.data.HttpProxy({
        url: 'url here', 
        method: 'POST'
    }),
    reader: new Ext.data.JsonReader({
        root: 'rows',
        idProperty: 'recordID'
    },[
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
      ])
});

And finally: are you sure, your store has been loaded when you try to retrieve records from it?

Try

frmClientStore.load({
    callback: function(rs) {
        console.log(rs);
        console.log(this.find('ClientID', '37'));
    }
});

نصائح أخرى

The way that you've listed should be correct. However, I should point out that the field name is case sensitive. It is also possible that it is searching for a string (as you've listed) instead of a number (which may be what you want).

Supposing that 'ClientID' is the correct field name, you should try the following:

var index = clientStore.find('ClientID', 37);

EDIT

Also, I've just noticed that something looks off about your JsonReader. Shouldn't it be more like this:

//...
reader: new Ext.data.JsonReader({
    root: 'rows',
    id: 'recordID'
    fields: [ //list fields here as part of the JsonReader
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
    ]
})
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top