C# 尝试连接使用Knockoutjs的两个跨度字段

C# 尝试连接使用Knockoutjs的两个跨度字段,c#,knockout.js,C#,Knockout.js,我刚刚开始使用knockout.js,我得到了很好的结果,但我有一个小问题: 我有一个JSON列表,用于构建模板: 以下是列表和制定列表的代码: public IEnumerable<dynamic> TheaterList { get; set; } List<TheaterTest> theaters = new List<TheaterTest>(); protected void Page_Load(object

我刚刚开始使用knockout.js,我得到了很好的结果,但我有一个小问题:

我有一个JSON列表,用于构建模板:

以下是列表和制定列表的代码:

 public IEnumerable<dynamic> TheaterList { get; set; }
        List<TheaterTest> theaters = new List<TheaterTest>(); 

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                getTheaters();
                TheaterList = theaters;
            }

        }

        protected void getTheaters()
        {
            theaters.Add(new TheaterTest()
            {
                theater_dist = "3",
                theater_name = "Regal Webster Place 11",
                theater_add1 = "1471 W. Webster Ave",
                theater_add2 = "",
                theater_city = "Chicago",
                theater_state = "Il",
                theater_postcode = "60614",
                theater_phone = "(762) 711-9180"
            });

            theaters.Add(new TheaterTest()
            {
                theater_dist = "4.2",
                theater_name = "Regal Washington Park 9",
                theater_add1 = "1341 W Webster Ave",
                theater_add2 = "",
                theater_city = "Chicago",
                theater_state = "Il",
                theater_postcode = "60614",
                theater_phone = "(762) 711-9180"
            });
public IEnumerable剧院列表{get;set;}
列表影院=新列表();
受保护的无效页面加载(对象发送方、事件参数e)
{
如果(iPostBack)
{
getthewers();
剧院列表=剧院;
}
}
受保护的真空加热器()
{
剧院。添加(新剧院测试()
{
剧院区=“3”,
剧院名称=“富豪韦伯斯特广场11号”,
剧院地址1=“西韦伯斯特大街1471号”,
剧院地址2=“”,
剧院城市=“芝加哥”,
剧院_state=“Il”,
剧院邮政编码=“60614”,
剧院电话=“(762)711-9180”
});
剧院。添加(新剧院测试()
{
剧院区=“4.2”,
剧院名称=“富豪华盛顿公园9号”,
剧院地址1=“西韦伯斯特大街1341号”,
剧院地址2=“”,
剧院城市=“芝加哥”,
剧院_state=“Il”,
剧院邮政编码=“60614”,
剧院电话=“(762)711-9180”
});
这是在.ascx中构建JSON的代码

<script>
    var d = {};
    d.theaterList = <%= Newtonsoft.Json.JsonConvert.SerializeObject(TheaterList) %>  ;
    $(document).ready(function () {

        ko.applyBindings(new theaterSel.TheaterModel(d.theaterList));

    });
</script>

var d={};
d、 剧院名单=;
$(文档).ready(函数(){
ko.applyBindings(新剧院、剧院模型(d.剧院列表));
});
这是我的模板:

<div class="theatre-info">
            <div class="theater-name">

                <a data-bind="attr: { href: ''}"><span class="theater-link" data-bind="    text: theater_name" /></a>

            </div>
            <div class="theatre-address" data-bind="text: theater_add1, text: theater_add2"></div>
            <div class="theatre-address" data-bind="text: theater_city + text: theater_state + text: theater_postcode"></div> 
            <div class="theatre-phone" data-bind="text: theater_phone"></div>
            <button>My Theatre</button>
        </div>
    </li>

我的剧院

我想连接剧院城市、剧院州和剧院邮政编码:我想我可以使用“ko.compute…但我不确定如何创建该函数。 任何帮助都将不胜感激


提前谢谢你。

是的,你走对了道路-

在您的视图模型中

var computedName = ko.computed(function () {
    return theater_city + ', ' + theater_state + ', ' + theater_postcode;
});
在你看来

<h1 data-bind="text: computedName"></h1>

非常感谢,这是我的想法,但我不知道函数如何知道这些值,因为它们来自JSON列表。我实际上是这样编码的。我只是需要保证。非常感谢!!