0

そのため、オブジェクトの名前を保持するプロパティをオブジェクトに追加しようとしています。これは、html名属性などの内部で使用されます。

setClientSideOpeningHours: =>
    newOpeningHours = {}
    existingOpeningHours = _.extend {}, @.get("opening_hours")
     _.each _.keys(existingOpeningHours), (item) ->
        newOpeningHours[item] = existingOpeningHours[item]
        newOpeningHours[item]["day"] = item
    console.log "openingHours.friday", newOpeningHours.friday,
                "openingHours.friday.day", newOpeningHours.friday.day
    @.set "clientside_opening_hours", newOpeningHours

Chromeでは、これはコンソールに出力されます。

openHours.fridayopeningHours.friday:オブジェクト{is_closed: "true"、proto:オブジェクト}openingHours.friday.day:金曜日

後で、モデルの外部で@ .model.toJSON()または@ .model.attributesを呼び出すと、dayプロパティが完全になくなります。ここで何が起こっているのですか?

編集:$。extend(true、...)で動作するようになりました

setClientSideOpeningHours: =>
    newOpeningHours = {}
    existingOpeningHours = $.extend true, {}, @.get("opening_hours")
    _.each .keys(existingOpeningHourshours), (item) =>
        newOpeningHours[item] = $.extend true, {}, existingOpeningHours[item]
        newOpeningHours[item].day = item
    @.set "clientside_opening_hours", newOpeningHours
4

0 に答える 0