PDA

View Full Version : [CLOSED] set combo selected value



susanz
Nov 11, 2014, 3:50 AM
I try to install a load handler to set selected value for comboBox. Is it right to use this.up('combo') ? I got "undefined is not a function " error.
Thanks
-susan



X.Panel()
.Title("Filters")
.Collapsed(false)
.Collapsible(false)
.BodyBorder(0)
.Items(
X.ComboBox()
.MessageBusListeners(new MessageBusListener
{
Name = "Filter." + Model.GridID,
Handler = "this.getStore().load();"
}
)
.Store(X.Store()
.Model(X.Model().Fields(new ModelField("name")))
.Proxy(X.AjaxProxy()
.Url (Url.Action("GetGridDimFilters", "Combo", new { gridId = @Model.GridID }))
.Reader(X.JsonReader().Root("data"))
)
.Listeners(ls =>
ls.Load.Handler = @"var combo = this.up('combo'); combo.setValue(records[0].get(combo.valueField));" // this does not work
)
)
)

Daniil
Nov 11, 2014, 3:37 PM
Hi @susanz,

There is no the .up() method in the Store API.

A store is the data layer and it is designed with the concept of loose coupling. In other words a Store doesn't have a reference to a component that it is wired up to.

If you already use MessageBus, I think your scenario is a good chance for that as well, to wire up the ComboBox and its Store.

Here is an example.

View

@{
var X = Html.X();
}

<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>

<script>
var onLoad = function(eventName, data) {
this.setValue(data.records[0].data[this.valueField]);
};
</script>
</head>
<body>
@X.ResourceManager()

@(X.ComboBox()
.QueryMode(DataLoadMode.Local)
.Store(X.Store()
.Model(X.Model().Fields("text", "value"))
.Proxy(X.AjaxProxy()
.Url(Url.Action("GetData"))
.Reader(X.JsonReader().Root("data"))
)
.Listeners(events => events.Load.BroadcastOnBus = "Store.Load")
)
.MessageBusListeners(new MessageBusListener
{
Name = "Store.Load",
Fn = "onLoad"
})
)
</body>
</html>


Controller

public ActionResult Index()
{
return this.View();
}

public ActionResult GetData()
{
return this.Store(new object[]
{
new
{
text = "Item 1",
value = 1
},
new
{
text = "Item 2",
value = 2
}
});
}

susanz
Nov 11, 2014, 7:00 PM
Thanks Daniil. That works great for me.
-szhang