小编Mat*_*nce的帖子

ko.subscribe儿童模型属性

寻找如何在knockoutjs中设置子模型的一个很好的例子.这包括绑定到儿童事件,例如我尚未能够正常工作的属性更新.

此外,在这种情况下绑定到单个子节点而不是数组会更好,但我不知道如何在没有foreach模板的情况下在html中设置它.

http://jsfiddle.net/mathewvance/mfYNq/

谢谢.

<div class="editor-row">
    <label>Price</label>
    <input name="Price" data-bind="value: price"/>
</div>

 <div class="editor-row">
    <label>Child</label>
    <div data-bind="foreach: childObjects"> 
        <div><input type="checkbox" data-bind="checked: yearRound" /> Year Round</div>
        <div><input type="checkbox" data-bind="checked: fromNow" /> From Now</div>
        <div>
            <input data-bind="value: startDate" class="date-picker"/> to 
            <input data-bind="value: endDate" class="date-picker"/>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)
var ChildModel= function (yearRound, fromNow, startDate, endDate) {
    var self = this;

    this.yearRound = ko.observable(yearRound);
    this.fromNow = ko.observable(fromNow);
    this.startDate = ko.observable(startDate);
    this.endDate = ko.observable(endDate);

    this.yearRound.subscribe = function (val) {
        alert('message from child model property subscribe\n\nwhy …
Run Code Online (Sandbox Code Playgroud)

javascript data-binding mvvm viewmodel knockout.js

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

如何将继承鉴别器映射为实体框架中的复合键?

是否可以使用父键和鉴别器值映射一对一的关系?我知道代码首先不喜欢具体类上的discriminator属性,只能在Map方法中引用它.

FlightTypes { Inbound = 1, Outbound = 2} 

public class Transaction
- int TransactionId
- int? InboundFlightId
- InboundTransactionFlight InboundFlight
- int? OutboundFlightId
- OutboundTransactionFlight OutboundFlight

public abstract class TransactionFlight
- TransactionFlightId

public class InboundTransactionFlight : Flight
- List<Transaction> InboundFor

public class OutboundTransactionFlight : Flight
- List<Transaction> OutboundFor

Entity<InboundTransactionFlight>().Map(m => m.Requires("FlightTypeId").HasValue(1));        
Entity<OutboundTransactionFlight>().Map(m => m.Requires("FlightTypeId").HasValue(2));
Run Code Online (Sandbox Code Playgroud)

/ *这是当前生成的* /

CREATE TABLE Transactions (
    TransactionId    int NOT NULL,
    InboundFlightId  int NULL,
    OutboundFlightId int NULL
)

CREATE TABLE TransactionFlights (
    TransactionFlightId int NOT …
Run Code Online (Sandbox Code Playgroud)

entity-framework

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