小编Ala*_*ski的帖子

使用knockout将对象添加到可观察数组

由于某种原因,我无法将对象传递给可观察数组.

function CalendarViewModel() {
var self = this;

self.event = {
    name : ko.observable(""),
    adress : ko.observable(""),
    startTime : ko.observable(""),
    endTime : ko.observable("")
}

self.events = ko.observableArray([

])

self.addEvent = function (event) {

    self.events.push(event);

    alert(self.events.length)
    alert(self.events[0].name());
 }
Run Code Online (Sandbox Code Playgroud)

我的看法:

 <fieldset class="add-event-fieldset">
            <div data-bind="with: event">
                <legend>Add Event</legend>
                <div style="text-align: center;">
                    <label class="title-label">What </label>
                </div>
                <div>
                    <label>Name: </label>
                    <input type="text" name="whatTxtBox" data-bind="value: name" />
                </div>
                <div>
                    <label>Where: </label>
                    <input type="text" name="whereTxtBox" data-bind="value: adress" />
                </div>
                <div style="text-align: center;">
                    <label class="title-label">When </label>
                </div>
                <div> …
Run Code Online (Sandbox Code Playgroud)

javascript ko.observablearray knockout.js

7
推荐指数
1
解决办法
3万
查看次数

如何在给定字符后选择子字符串

我想使用正则表达式将子字符串保存到javascript变量,除非有不同/更简单的方法.例如,我有这样的链接:http: //www.youtube.com/watch?v = sEHN4t29oXY&feature = related

我想只得到sEHN4t29oXY&feature =相关所以我想我必须检查出现的第一个等号然后将该字符串的其余部分保存到变量中..请帮忙,谢谢

javascript regex

5
推荐指数
2
解决办法
1万
查看次数

当我需要使用绑定重绘html时重新绑定jout

我有一种情况,我动态构建一个div容器,其他html元素内部绑定到我的淘汰视图模型.它可以解决我在我的挖空视图模型上调用一个需要重绘整个div的方法的问题.重绘淘汰赛停止工作后.

例如:

 calendar += ('<div class="month-nav-container"><div class="nav-prev" data-bind="click:          $root.showPreviousMonthOnPrevMonthBtnClick" ><<<</div><span class="month-name-calendar">' + monthNames[month] + '</span><div class="nav-next" data-bind="click: $root.showNextMonthOnNextMonthBtnClick" >>>></div></div>');
Run Code Online (Sandbox Code Playgroud)

我建立了我的日历控件,当然这只是其中的一部分,但我希望你能得到一般的想法.

我的淘汰视图模型方法:

self.showPreviousMonthOnPrevMonthBtnClick = function () {
    alert("prev");
    var $calendar = $("#calendar");
    $calendar.empty();

    ////// previous month
    if (self.calendarDisplayDate.month == 0) {
        $calendar.calendarWidget({ month: 12, year: self.calendarDisplayDate.year - 1 });
    } else {
        $calendar.calendarWidget({ month: self.calendarDisplayDate.month - 1, year: self.calendarDisplayDate.year});            
    }

}
Run Code Online (Sandbox Code Playgroud)

在我的页面加载我构建我的日历div,然后我调用ko.applyBindings()到我的视图模型,它的工作原理.但是,当我点击上一个月的方法来调整需要根据正确的月份重绘日历的btn时,淘汰赛停止工作.我重绘了包含所有敲除绑定的整个父div.有谁知道我的问题的解决方案.我需要重新绘制里面有KO绑定的div,所以也许我正在寻找的是Knockout的某种绑定刷新方法?

javascript data-binding knockout.js

4
推荐指数
1
解决办法
1万
查看次数

MetadataType缺少程序集引用

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.ComponentModel.DataAnnotations;




  namespace yplaylist.Models
  {
     [MatadataType(typeof(Song_Validation))]
     public partial class Song
     {

     }

     public class Song_Validation
     {



     }
 }
Run Code Online (Sandbox Code Playgroud)

MetadataType突出显示,它找不到缺少using指令或程序集引用?我错过了什么?

asp.net-mvc-3

3
推荐指数
1
解决办法
2190
查看次数

如何保护asp.net mvc 3网站免受网址查询?

我的问题是,当人们输入像home/DeleteSong这样的url?id = 139时,他们会在家庭控制器中进行操作,并且可以删除歌曲和内容.我相信我可以使用[authorize]属性,但是登录用户仍然可以输入url来使用我不希望发生的操作.我主要使用ajax请求与服务器通信,所以我应该检查我的动作是否有ajax请求,如果它是让它做的话,否则做其他事情.我想以一种方式设置我的项目,当用户键入任何网址时,我只会重定向到主页..我该怎么做,这会解决我的问题吗?

我的行动:

 [HttpPost]
    public ActionResult DeleteTopTenFav(int id)
    {
        var song = repository.GetTopTenFav(id);

        var points = repository.FindPoints(song.UserName);
        foreach (var item in points)
        {
            item.TopTenFav = null;
        }

        repository.DeleteTopTenFav(song);
        repository.Save();
        return RedirectToAction("Index");
    }
Run Code Online (Sandbox Code Playgroud)

我的jquery ajax删除功能:

   $("#topTenContainer").on("click", ".btnDeleteTopTenFavSong", function () {
    var button = $(this);
    var songId = $(this).attr('name');

    $.ajax({
        beforeSend: function () { ShowAjaxLoader(); },
        type: 'POST',
        url: "/Home/DeleteTopTenFav/",
        data: { id: songId },
        success: function () { HideAjaxLoader(), ChangeColorShowMsg("green"), ShowSuccessMsgAndReplaceTopTenSong("Song deleted successfully", button) },
        error: function () { HideAjaxLoader(), …
Run Code Online (Sandbox Code Playgroud)

security url asp.net-mvc-3

1
推荐指数
1
解决办法
926
查看次数

javascript/jquery函数范围

 function onMouseClickFunction() {

    $mapCanvas.click(function (e) {
        var x = cursor.getCursorPositionInCanvasX(e.pageX),
            y = cursor.getCursorPositionInCanvasY(e.pageY);
Run Code Online (Sandbox Code Playgroud)

这个例子中的变量范围是函数onMouseclickFunction还是jquery的匿名函数?

我的意思是javascript在其父函数的顶部使用提升创建变量,那么在这个例子中提升的位置是什么?

javascript jquery scope

1
推荐指数
1
解决办法
105
查看次数