razorview以jquery模型字段为条件

时间:2014-07-23 18:59:16

标签: javascript jquery razor

我有一些像这样的jquery ......

init: function () {
        var self = this;

        this.dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: $.url.action(self.controller, self.action, { projectId: projectId }),
                    cache: false,
                    dataType: "json"
                }
            },
            schema: {
                model: {
                    id: "StudyId",
                    fields: {
                        Name: { type: "string" },
                        ViewName: { type: "string" },
                        Description: { type: "string" },
                        ViewDescription: { type: "string" },
                        UpdateDate: { type: "date" },
                        StudyId: { type: "number" },
                        NextMilestoneName: { type: "string" },
                        NextMilestoneDate: { type: "date" },
                        StudyStatus: { type: "string"}
                    }
                }
            },
            sort: { field: "UpdateDate", dir: "desc" },
            sortable: { mode: "single", allowUnsort: false },
            pageSize: 4
        });

我想有条件地显示这个,具体取决于ViewDescription是否为空......

@if (!String.IsNullOrEmpty(????))
{
    <span><strong>@Resources.Resources.Description1 </strong>#:ViewDescription#</span>
     <br>
}

我无法弄明白!我将什么用于访问ViewDescription?

1 个答案:

答案 0 :(得分:0)

根据您发布的内容,您似乎正在尝试利用基于在页面加载之前不存在的信息的剃刀视图,甚至直到该Kendo控件调用“Read()”。 Razor视图将在javascript执行之前构建。但是,在执行该代码之后,您可以在JS中执行类似的操作。 (另请查看:http://docs.telerik.com/kendo-ui/api/framework/datasource#events-change

init:function(){         var self = this;

    this.dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: $.url.action(self.controller, self.action, { projectId: projectId }),
                cache: false,
                dataType: "json"
            }
        },
        change: function(e) {
         if(e.items["ViewDescription"]!=null){
             $("#IDofDivHere").append("<span><strong>@Resources.Resources.Description1</strong>"+e.items["ViewDescription"]+"</span><br>");
         }
        },
        schema: {
            model: {
                id: "StudyId",
                fields: {
                    Name: { type: "string" },
                    ViewName: { type: "string" },
                    Description: { type: "string" },
                    ViewDescription: { type: "string" },
                    UpdateDate: { type: "date" },
                    StudyId: { type: "number" },
                    NextMilestoneName: { type: "string" },
                    NextMilestoneDate: { type: "date" },
                    StudyStatus: { type: "string"}
                }
            }
        },
        sort: { field: "UpdateDate", dir: "desc" },
        sortable: { mode: "single", allowUnsort: false },
        pageSize: 4
    });

因此,我们正在连接在检索数据时应该触发的kendo事件更改(如ajax中的成功回调),然后将您想要的数据附加到任何您希望的位置