1

I am trying to integrate select2 in backgrid.js. Backgridjs has extension support for select2 and the code for that is

{
   name: "gender",
    cell: Backgrid.SelectCell.extend({
    optionValues: [["Male", "m"], ["Female", "f"]]
     }),
   label: "Gender (SelectCell)"
 }

so based on this i tried something like the below since i have to load values to select2 box from the server

var FetchSecurities = Backbone.Model.extend({
    url : Hexgen.getContextPath("/referencedata/securities")
});
var fetchSecurities = new FetchSecurities();

{
        name: "security",
        label: "Security",
        cell: Backgrid.Extension.Select2Cell.extend({

            optionValues: fetchSecurities.fetch({
                success : function() {
                    for(var objectPlace in fetchSecurities.attributes) {
                        [[fetchSecurities.attributes[objectPlace].security],[fetchSecurities.attributes[objectPlace].security]];
                    }
                }
            }),
          })
    }

but i get this exception, I am sure i make mistake when constructing the value for the select2 box but don't know how to fix it, Please help me to get it done.

Uncaught TypeError: 'optionValues' must be of type {Array.<Array>|Array.<{name: string, values: Array.<Array>}>}
JanR
  • 6,052
  • 3
  • 23
  • 30
Java Questions
  • 7,813
  • 41
  • 118
  • 176
  • fetchSecurities.fetch doesn't return a helpful result, clearly. Investigate and debug! That's up to you to resolve. – doppelgreener Jun 26 '13 at 05:43
  • I feel this question is not going to be very useful to other programmers, and should possibly be closed, but I'm not sure what the status is of questions like this following the meta discussions that've taken place around the new closing system. – doppelgreener Jun 26 '13 at 05:46
  • You mean to say that the `fetchSecurities.fetch` has to value accordingly ?? – Java Questions Jun 26 '13 at 05:47
  • 1
    Well... you're trying to pass something to optionValues that must be in a specific format, that something is the result of fetchSecurities.fetch, and that something being returned by fetchSecurities.fetch is not being accepted. Naturally, fetchSecurities.fetch is not returning a compatible object. The statements in your `for` loop are just creating an array that goes nowhere, etc. Maybe you should be doing this very differently. – doppelgreener Jun 26 '13 at 05:50
  • Thanks `Jonathan` i got it, the return values not the expected format, the return value must be an expected format of `optionValues' am i correct?? – Java Questions Jun 26 '13 at 05:59
  • Jonathan, I am sorry if this disturbs you, how should i return value so that this `{Array.|Array.<{name: string, values: Array.}>} ` matches. I am actually using java to return values – Java Questions Jun 26 '13 at 06:03
  • By returning an array, or an array of objects fitting that format? – doppelgreener Jun 26 '13 at 06:11
  • it should actually be a JSON string which is take care by spring MVC, this is also one of the reason why i am confused. please provide me with simple sample – Java Questions Jun 26 '13 at 06:14

0 Answers0