如何通过价值烬视图控制器 [英] how to pass value ember view to controller
问题描述
我在pretty烬JS开发新的。
我已经做了视图下方code
{{视图中选择内容=模型提示=请选择一个名称selectionBinding =optionValuePath =content.bodyoptionLabelPath =content.title}}
使用下面的Json
帖= [{
标题:拉贾
身体:有很多点菜软件环境在这个世界上。
},{
标题:没兑现的承诺,
身体:詹姆斯Coglan写在node.js中承诺了一个长篇文章
}];
和路由器
App.InRoute = Ember.Route.extend({
型号:功能(){ 返回岗位;
}
});
我的要求是传递一个组合框中选择值控制器
App.InController = Ember.Controller.extend({警报(组合框中选择的项目)
});
以及如何在我访问值apicontoller在.NET MVC 4
公共类ValuesController:ApiController
{
字符串值=组合框中选择的值
}
您选择视图的值属性需要绑定到控制器上的属性:
以下内容添加到您的视图的属性:值=将selectedItem
在你的控制器:
添加将selectedItem
App.InRoute = Ember.Route.extend({ 将selectedItem:空, 型号:功能(){
返回岗位;
}
});
现在,您的所有设置将其发送给您的API终点。你可以创建一个行动处理器,并使其发生在那里。下面是一个简单的例子:
App.InRoute = Ember.Route.extend({ 将selectedItem:空, 型号:功能(){
返回岗位;
}, 动作:{
提交:功能(){
$阿贾克斯('/ API / yourEndPoint',{类型:POST,数据:{体:this.get('将selectedItem')}})
}
}
});
在你把手模板
<按钮{[动作'提交'}}>提交< /按钮>
在您的.NET API控制器
公共IHTTPActionResult邮政(字符串体){
//.NET's模型绑定将正确拉出身体键值对的值。
//现在用身体做随你的便。
}
你真的应该考虑使用烬-数据,它吓坏真棒。
I am new in pretty ember js development .
I have done view below code
{{view "select" content=model prompt="Please select a name" selectionBinding="" optionValuePath="content.body" optionLabelPath="content.title"}}
using following Json
posts = [{
title: "Raja",
body: "There are lots of à la carte software environments in this world."
}, {
title: "Broken Promises",
body: "James Coglan wrote a lengthy article about Promises in node.js."
}];
and Router
App.InRoute = Ember.Route.extend({
model: function () {
return posts;
}
});
My Requirement is passing that combo box selected value to controller
App.InController = Ember.Controller.extend({
alert("combobox selected item")
});
And how an i access that value apicontoller in .net mvc 4
public class ValuesController : ApiController
{
string value= combo box selected value
}
Your "select" view's value attribute needs to be bound to a property on the controller:
add the following to your view's attributes: value=selectedItem
In your controller:
Add "selectedItem"
App.InRoute = Ember.Route.extend({
selectedItem: null,
model: function () {
return posts;
}
});
Now your all set to send it to your Api end point. You could create an action handler and make it happen there. Here is a quick example:
App.InRoute = Ember.Route.extend({
selectedItem: null,
model: function () {
return posts;
},
actions: {
submit: function(){
$.ajax('/api/yourEndPoint', {type: 'POST', data: {body: this.get('selectedItem')} })
}
}
});
In your Handlebars template
<button {[action 'submit'}}>Submit</button>
In your .NET API Controller
public IHTTPActionResult Post(string body){
//.NET's Model Binder will correctly pull out the value of the body keyvalue pair.
//Now do with "body" as you will.
}
You should really look into using Ember-Data, it's freaking awesome.
这篇关于如何通过价值烬视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!