Aug 18, 2015, 2:21 PM
RESTful Store question
Hi Guys,
I have a question about RESTful Store. Here is my code.
Thanks
I have a question about RESTful Store. Here is my code.
<script>
var onWrite = function(store, operation) {
var record = operation.getRecords()[0],
name = Ext.String.capitalize(operation.action),
verb;
if (name == 'Destroy') {
record = operation.records[0];
verb = 'Destroyed';
} else {
verb = name + 'd';
}
Ext.net.Notification.show({ title: name, html: Ext.String.format("abc") });
};
var StockItemNameSelect = function(combo, record, index) {
var val = combo.getValue();
var g = Ext.getCmp('myGrid');
//var sm = g.getSelectionModel();
//var rec = sm.selection.record;
var rec = g.getSelectionModel().getSelection()[0];
rec.set('StockItemName', val);
alert(rec.get('StockItemName'));
//rec.set('common', 'whatever');
};
</script>
@(X.Store()
.ID("StockItemStore")
.Model(
Html.X().Model()
.Fields(
X.ModelField().Name("text").Mapping("Text").Type(ModelFieldType.String),
new ModelField("Stockcode", ModelFieldType.String),
new ModelField("Name1", ModelFieldType.String),
new ModelField("Name2", ModelFieldType.String),
new ModelField("Catid", ModelFieldType.Int),
new ModelField("Unitid", ModelFieldType.Int),
new ModelField("UnitType", ModelFieldType.String),
//new ModelField("Unit", ModelFieldType.String),
new ModelField("Supplierid", ModelFieldType.Int),
new ModelField("Price", ModelFieldType.Float),
new ModelField("Isenable", ModelFieldType.Int),
new ModelField("Leastinventory", ModelFieldType.Float)
//,
//new ModelField("CategoryName1", ModelFieldType.String),
//new ModelField("CategoryName2", ModelFieldType.String)
)
)
.Proxy(X.AjaxProxy()
.Url(Url.Action("GetStockItemList"))
.Reader(X.JsonReader().Root("data"))
)
)
@(
X.GridPanel()
.ID("myGrid")
.Height(300)
.Store(
Html.X().StoreForModel().Control(s =>
{
s.AutoSync = true;
s.Parameters.Add(new StoreParameter("id", "Ext.decode(Ext.util.Cookies.get('ItemCode'))", ParameterMode.Raw));
s.Proxy.Add(
new RestProxy
{
AppendAction = false,
Reader =
{
new JsonReader
{
Root = "data",
MessageProperty = "message"
}
},
API =
{
Read = Url.Action("Read"),
Update = Url.Action("Update"),
Create = Url.Action("Create"),
Destroy = Url.Action("Destroy")
},
Writer =
{
new JsonWriter
{
AllowSingle = true
}
}
}
);
s.Listeners.Write.Fn = "onWrite";
})
)
.ColumnModel(
X.NumberColumn()
.Text("æ•°é‡")
.DataIndex("Qty")
.Flex(1)
.Editor(
Html.X().TextField().AllowBlank(false)
)
.Width(200),
X.Column()
.Text("原料")
.DataIndex("StockItemName")
.Flex(1)
.Editor(
X.ComboBox()
//.TriggerAction(TriggerAction.All)
.StoreID("StockItemStore")
.ValueField("Stockcode")
.DisplayField("Name2")
.Listeners(ls =>
{
ls.Select.Fn = "StockItemNameSelect";
})
)
.Width(200)
)
.TopBar(
Html.X().Toolbar()
.Items(
Html.X().Button()
.Text("Add")
.Icon(Icon.Add)
.Handler("this.up('grid').store.insert(0, new Matching());this.up('grid').editingPlugin.startEdit(0, 0);"),
Html.X().Button()
.ItemID("btnRemove")
.Text("Delete")
.Icon(Icon.Exclamation)
.Handler("this.up('grid').deleteSelected();")
)
)
.Plugins(
Html.X().RowEditing()
.Listeners(l =>
{
l.CancelEdit.Handler = "if(e.record.phantom){e.store.remove(e.record);}";
})
)
)
Strange thing is when I select a value in combox, the update function in server-side will be executed. Why not when I click the 'Update' button?Thanks