1

I've been struggling all afternoon with this problem and couldn't find any viable solution online, so here we go. I'll try my best to be thorough regarding my problem as I already boiled down its main elements (in other words, some of my code here is gonna be a simplified example and I'm gonna tell bits of the story here and there for better understanding). First off, I use EXT.NET MVC model and I use markup to a great extent. So, here's my store (actual code):

        <ext:Store ID="storeActivityProjectHistory" runat="server" UseIdConfirmation="true">
            <Reader>
                <ext:JsonReader IDProperty="idProject">
                    <Fields>
                        <ext:RecordField Name="idActivity" Type="Int" />
                        <ext:RecordField Name="idProject" Type="Int" />
                        <ext:RecordField Name="nmProject" Type="String" />                             
                        <ext:RecordField Name="csStatus" Type="String" />                        
                        <ext:RecordField Name="dsDetails" Type="String" />
                        <ext:RecordField Name="dtDate" Type="Auto" DateFormat="MM/yyyy" />                              
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>   

A bit of insight: an Activity might contain several Projects. Usually one would expect the other way around, but it is not. And this is the grid I linked to this store (I removed several tags from this one, for simplicity's sake):

    <ext:GridPanel ID="grdActivityProjectHistory" runat="server" StripeRows="true" Title='<%# Html.GetText("History") %>' Width="621" AutoHeight="true" 
        StoreID="storeActivityProjectHistory">
        <ColumnModel>
            <Columns>
                <ext:Column ColumnID="idActivity" DataIndex="idActivity" Hidden="true" />
                <ext:Column ColumnID="idProject" DataIndex="idProject" Hidden="true" />
                <ext:Column ColumnID="nmProject" Header="Project" DataIndex="nmProject" Width="250" />
                <ext:Column ColumnID="dsDetails" DataIndex="dsDetails" Hidden="true" />
                <ext:Column ColumnID="csStatus" Header="Status" DataIndex="csStatus" Width="75" />
                <ext:DateColumn ColumnID="dtDate" Header="Date" DataIndex="dtDate" Width="75" Format="MM/yyyy" />
            </Columns>
        </ColumnModel>
    </ext:GridPanel>

Now, some explanation is due: whenever an Activity is created, the user might link one or several Projects to it. Also, he can change this LINK's status to flag whether the project is active or inactive within the Activity. Changes in this link must be stored in a history, which is what the grid and store above provide support to.

Whenever this link is created, it must be active and have a default detail ("Record created"). Since it is a default behavior and we use a lot of stored procedures to deal with the DB, I figured that whenever a new link is created, I could just insert these values straight into the database from the SP itself. In other words, whenever a link is created, there will already be one record in history.

This is how I load said record into the store upon loading the activity and that is, what I suppose, part 1 of what messes things up (don't worry about the projectId variable):

    var fillActivityProjectStore = function(projectId) {
        var activityProjectHistoryList;
        currentProjectHistoryList = new Array();

        if (loadedActivity.activityProjectHistoryList!= null) {
            activityProjectHistoryList = loadedActivity.activityProjectHistoryList.Original;
            activityProjectHistoryList.forEach(function(activityProjectHistory) {
                if (activityProjectHistory.cdProject == projectId) 
                    currentProjectHistoryList.push(activityProjectHistory);
            });
            storeActivityProjectHistory.loadData(currentProjectHistoryList);
        }
    }

The explanation to this apparent mess: loadedActivity.activityProjectHistoryList.Original holds all history information of all projects linked to the current loaded activity and here I select the information relative only to one of those projects and load into the store.

And, for the gran finale, whenever I try to change the status of this link (which should add a second line in the grid, under the current line already loaded), is when I recieve the dreadful "Uncaught TypeError: Cannot read property 'data' of undefined"

This is how I try to add a new line:

    var addNewHistoryRecord= function() {
        if (selectedLineIndex> -1) {
            var record= storeProjects.getAt(selectedLineIndex).data;
            var recordHistory= {
                idActivity: 0, //Server-side handles it
                idProject: record.idProject,
                nmProject: record.nmProject,
                dsDetails: dsDetailsField.getValue(),
                csStatus: csStatusField.getValue(),
                dtDate: dtDateField.getValue()
            }

            storeActivityProjectHistory.addRecord(recordHistory); // <--RIGHT HERE!
        }
    }

Well, I'm sorry about the overly long post and the stupid variable names, I had to hastly translate them to english because we use our native language in code (which sucks). I'm pretty sure that the relationship between the storeActivityProjectHistory.loadData and storeActivityProjectHistory.addRecord methods are my problem, but I just don't know what to do about it. Thanks in advance and if more code is needed, I'll post more code (for instance, one might notice some global variables and a "storeProject" in the last javascript method that I hadn't mentioned before, but I don't think it is actually relevant). Hope you guys can help!

Edit: As instructed, I have changed store.addRecord to store.add and now it returns the following error in the same point: Uncaught TypeError: Object #Object has no method 'join' Any ideas?

4

1 回答 1

2

好的,我找到了答案。感谢 Reimius 让我不再懒惰并真正关注文档。通用对象无法与 store.add() 一起使用,需要 Ext.data.Record 的子类实例。

为了做到这一点,这是我遵循并在不到 10 分钟内解决了我的问题的简洁模板:http ://docs.sencha.com/extjs/3.4.0/#!/api/Ext.data.Record-静态方法创建

即使文档本身说 store.add 接受 Ext.data.Record[],我也没有使用它,在我以正确的方式创建对象(即 recordHistory)之后,仅仅是 storeActivityProjectHistory.add(记录历史)成功了。

于 2013-07-03T18:18:18.357 回答