So I have a JsonRest store with a dgrid attached to it. I use php and the yii framework.

If I fire a PUT I get a response formatted like this: [{id: 1, abbreviation: 'FL' }] Is that the correct form for the row to be updated? Or should I get only {id: 1, abbreviation: 'FL' } as a response?

Thanks!

Update #1:

    <div
    data-dojo-type="dijit.MenuBar"
    data-dojo-props="region:'top', layoutPriority:2, style:'margin-top: 10px'">
        <div
            id="OrderButton"
            data-dojo-type="dijit.form.Button">
            <span>Submit Order</span>
            <script type="dojo/on" data-dojo-event="Click">
                handleFinalizeOrder();
            </script>
        </div>
     <span class="right">Package Price: 20$ + 1$/pic</span><span id="results"></span>
</div>

<div id="imageList"></div>
<?php $this->beginDojoScript() ?>
<script type="text/javascript">
    require([
    'dojo/parser',
    'dojo/dom-construct',
    'dojo/dom-style',
    'dojo/_base/declare',
    'dojo/_base/xhr',
    'dojo/_base/loader',
    'dojo/_base/Deferred',
    'dojo/data/ItemFileWriteStore',
    'dojo/store/util/QueryResults',
    'dijit/Toolbar',
    'dijit/Tree',
    'dijit/TooltipDialog',
    'dijit/layout/StackContainer',
    'dijit/layout/ContentPane',
    'dijit/form/Button',
    'dijit/tree/ForestStoreModel',
    'dijit/form/Form',
    'dijit/form/ValidationTextBox',
    'dijit/form/DropDownButton',
    'dijit/form/CheckBox',
    'dojox/form/Uploader',
    'dojox/form/uploader/plugins/IFrame',
    'dgrid/OnDemandGrid',
    'dgrid/Selection',
    'dojo/on',
    'dgrid/editor',
    'dgrid/List',
    'dgrid/tree',
    'dgrid/Keyboard',
    'dijit/form/HorizontalSlider',
    'dijit/form/NumberSpinner',
    'dgrid/OnDemandGrid',
    'dojo/store/Memory',
    'dojo/store/Observable',
    'dijit/form/FilteringSelect',
    'dojo/data/ObjectStore',
    'dijit/Dialog',
    'dojo/store/Cache',
    'dojo/store/JsonRest',
    'dojo/domReady!'
], function(parser, domConstruct, domStyle, declare, xhr,
            loader, Deferred,ItemFileWriteStore, QueryResults, Toolbar, Tree, TooltipDialog,
            StackContainer, ContentPane, Button,
            ForestStoreModel, Form, ValidationTextBox, DropDownButton, CheckBox,
            Uploader, UploaderIFramePlugin, OndemandGrid, Selection, on, editor,
            List, tree, Keyboard, Slider, NumberSpinner, Grid, Memory,
            Observable, FilteringSelect, ObjectStore, Dialog, Cache, JsonRest) {
    /* Declaration */
    filetypeStore = Observable(new Memory({
            idProperty: "pictype",
            labelProperty: "name",
            data: [
                { "pictype": "1", "name": "Paperpic" },
                { "pictype": "3", "name": "DVD" }
            ]
    }));
    filesubtypeStore = Observable(new Memory({
            idProperty: "picsubtype",
            labelProperty: "name",
            data: [
                { "picsubtype": "1", "pictype": "1", "name": "10x15" },
                { "picsubtype": "2", "pictype": "1", "name": "13x18" },
                { "picsubtype": "3", "pictype": "1", "name": "20x30" },
                { "picsubtype": "4", "pictype": "1", "name": "30x45" },
                { "picsubtype": "10", "pictype": "3", "name": "DVD" }
            ]
    }));
    var columns = [
        {
            label: 'Picture',
            field: 'filename',
            formatter: function(filename){
                return '<div class="icon" style="background-image:url(<?php echo Yii::app()->baseUrl ?>/images/client/thumbnails/' + filename + ');"><a class="iconlink" href="<?php echo Yii::app()->baseUrl ?>/images/client/' + filename + '">&nbsp;</a></div>';
            }
        },
        editor({
            label: 'Type of pic', autoSave: false, field: 'pictype',
                widgetArgs: {
                    store: filetypeStore, autoComplete: true, required: true, maxHeight: 150, style: "height: 20px; width: 120px;"
                },
            }, FilteringSelect),
        editor({
            label: 'Size of pic', autoSave: true, field: 'picsubtype',
                widgetArgs: {
                    store: filesubtypeStore, autoComplete: true, required: true, maxHeight: 150, style: "height: 20px; width: 120px;"
                },
            }, FilteringSelect),
        {
            label: 'Price/pcs',
            field: 'picprice',
            formatter: function(picprice){
                return '<span class="pic_price">' + picprice + '</span>';
            }
        },
        editor({
            label: 'Number of pics',
            autoSave: true,
            field: 'piccount',
            widgetArgs: {
                class: 'pic_count',
                style: 'width: 4em;',
                constraints: {
                    min:1,
                    max:100,
                    places:0
                }
            },
        }, NumberSpinner),
    ];
    /* Model */
    collectionId = <?php echo $colID; ?>;
    var userMemoryStore = Memory();
    var userJsonRestStore = JsonRest({idProperty: "id", target: "<?php echo $this->createUrl('/orderCollectionOrder/handleOrderedImages') ?>?id=" + collectionId + "&picid="});
    var imageStore = Cache(userJsonRestStore, userMemoryStore);
    window.grid = new (declare([editor, ObjectStore, OndemandGrid, Selection]))({
            store: imageStore,
            getBeforePut: false,
            columns: columns
    }, "imageList");
    parser.parse();
    grid.on(".dgrid-content .iconlink:click", function (evt) {
        evt.preventDefault();
        var data = dojo.getAttr(this, "href");
        var dlg = new Dialog({
            title: "Pic: " + data.substr(15),
            className:"dialogclass",
            content: '<img src="' + data + '">'
        });
        dlg.show();
    });
});
</script>
<?php $this->endDojoScript() ?>

So, if I change the second filteringselect, the put fires correctly. Contents of put in firebug:

{"id":"1","categoryId":"2","collectionId":"146","fileid":"20737","pictype":"3","picsubtype":"2","filename":"pic_143_resize.jpg","filetype":"DVD","filesubtype":"30x45","picprice":"2000","piccount":"2"}

Response:

{"id":"1","categoryId":"2","collectionId":"146","fileid":"20737","pictype":"3","picsubtype":"2","filename":"pic_143_resize.jpg","filetype":"DVD","filesubtype":"13x18","picprice":"300","piccount":"2"}

So I get the response, but the dgrid does not get updated... Should I add an Observable store as well?

Thanks!

有帮助吗?

解决方案

This actually comes down to logic in dojo/store/Observable in this case. Observable will do one of two things in response to put calls:

  • If the server request resolves to an object, this object will be passed to notify (which the grid will pick up)
  • Otherwise, the object originally passed to put will be passed through to notify

You're falling into the first case, since arrays are objects - in which case, as you suspected, you'll want just the object itself, not an array. The array doesn't make much sense anyway, since put operates on a single item.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top